Worker
Reference doc for the `sst.cloudflare.Worker` component.
The Worker
component lets you create a Cloudflare Worker.
Minimal example
Link resources
Link resources to the Worker. This will handle the credentials and allow you to access it in your handler.
You can use the SDK to access the linked resources in your handler.
Enable URLs
Enable worker URLs to invoke the worker over HTTP.
Bundling
Customize how SST uses esbuild to bundle your worker code with the build
property.
Constructor
Parameters
-
name
string
-
args
WorkerArgs
-
opts?
ComponentResourceOptions
WorkerArgs
build?
Type Input
<
Object
>
Configure how your function is bundled.
SST bundles your worker code using esbuild. This tree shakes your code to only include what’s used.
build.banner?
Type Input
<
string
>
Use this to insert a string at the beginning of the generated JS file.
build.esbuild?
Type Input
<
BuildOptions
>
This allows you to customize esbuild config that is used.
build.loader?
Type Input
<
Record
<
string
, Loader
>
>
Configure additional esbuild loaders for other file extensions. This is useful
when your code is importing non-JS files like .png
, .css
, etc.
build.minify?
Type Input
<
boolean
>
Default true
Enable or disable if the worker code is minified when bundled.
domain?
Type Input
<
string
>
Set a custom domain for your Worker. Supports domains hosted on Cloudflare.
environment?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs that are set as Worker environment variables.
They can be accessed in your function through env.<key>
.
handler
Type Input
<
string
>
Path to the handler file for the worker.
The handler path is relative to the root your repo or the sst.config.ts
.
link?
Type Input
<
any
[]
>
Link resources to your worker. This will:
- Handle the credentials needed to access the resources.
- Allow you to access it in your site using the SDK.
Takes a list of components to link to the function.
transform?
transform.worker?
Type WorkerScriptArgs
|
(
args
:
WorkerScriptArgs
=>
void
)
Transform the Worker resource.
url?
Type Input
<
boolean
>
Default false
Enable a dedicated endpoint for your Worker.
Properties
nodes
nodes.worker
Type Output
<
WorkerScript
>
The Cloudflare Worker script.
url
Type Output
<
undefined
|
string
>
The Worker URL if url
is enabled.
SDK
The following are accessible through the SDK at runtime.
url
Type undefined
|
string
The Worker URL if url
is enabled.