Runtimes
Cloudflare Workers
Run on Workers. export default app, c.env and c.executionCtx, and deploying
Export the app as is. Workers calls app.fetch(request, env, ctx).
import { } from "@senrijs/senri";
const = ();
.("/", () => "Hello, Workers!");
export default ;npx wrangler dev # http://localhost:8787 (the template's npm run dev)
npx wrangler deploy # deploy (the template's npm run deploy)For a new app, the template is the quickest way.
npm create senri@latest my-app -- --template workersc.env and c.executionCtx
Variables and bindings in wrangler.jsonc are available as c.env. Type them with createApp<{ Bindings: Env }>().
import { } from "@senrijs/senri";
type = { : string };
const = <{ : }>();
.("/", (, ) => {
..(()); // work that continues after the response
return ..GREETING;});
export default ;To also type the variables used with c.set() / c.get(), write createApp<{ Bindings: Env; Variables: { user: User } }>().
Differences on Workers
- Development mode: Workers cannot read
NODE_ENV, sodevtools()gives development output only for requests tolocalhost(wrangler dev). Error pages appear, but without the code. There is no/_senridashboard - Bundle size: wrangler bundles everything into one file, so leaving
dev: devtools()in also bundles the development code. Remove it from production builds - Static files: use Workers Static Assets instead of
@senrijs/senri/static - IP:
getIp(c)from@senrijs/senri/ipreadsCF-Connecting-IP, which Cloudflare adds