includeBytes
The includeBytes() function is used embed a file as a Uint8Array.
Note: Can only be used during build-time initialization, not when processing requests.
SECURITY:
includeBytes()is fully sandboxed to prevent access to files outside the directory that containsfastly.toml. All other files within that scope will be accessible, including through..and symlink navigation, including potentially sensitive files such as.env.
Syntax
includeBytes(path)
Parameters
path: string- The path to include, relative to the Fastly Compute application's top-level directory during build-time initialization.
Return value
Returns a Uint8Array
Examples
In this example we include the README.md file as a Uint8Array and use it for the body in the response we return to the client.
/// <reference types="@fastly/js-compute" />
import { includeBytes } from "fastly:experimental";
const readme = includeBytes('README.md');
async function app() {
return new Response(readme);
}
addEventListener("fetch", event => event.respondWith(app(event)));