Add a Deno demo for fetch-router - #11653
Open
kuboon wants to merge 5 commits into
Open
Conversation
Adds `packages/fetch-router/demos/deno`, a Deno counterpart to the existing Node, Bun, and Cloudflare Workers fetch-router demos. It runs the same blog application so the router, middleware, and route helpers are shown to be runtime-agnostic, with only the server entry point being Deno-specific. - `main.ts` serves `router.fetch` through `Deno.serve()` and shuts down gracefully on SIGINT/SIGTERM (SIGTERM is skipped on Windows, where Deno does not support it). - `deno.json` sets `nodeModulesDir: "manual"` so Deno resolves the `@remix-run/*` packages from the pnpm workspace's `node_modules`, and defines dev/start/typecheck tasks with explicit permission flags. - Static assets are served with `staticFiles()` from `@remix-run/static-middleware` rather than a hand-rolled file handler. - The demo defines no `typecheck`/`test` package scripts, so recursive workspace runs stay green on machines without Deno installed.
A router is already a `{ fetch }` object, which is the default export shape
`deno serve` expects, so the demo does not need its own server entry point.
`main.ts` now re-exports the router as the default export and the `dev`/`start`
tasks use `deno serve --port 44100`, which also means Deno owns the listener
and the graceful shutdown on SIGINT/SIGTERM that `main.ts` implemented by hand.
`deno serve` provides its own network access, so the tasks no longer pass
`--allow-net`.
Static imports do not need read permission, so the only filesystem access the demo makes at runtime is `staticFiles()` reading `./public`. Env access is limited to the four variables the `logger()` middleware inspects for terminal color detection.
`deno serve` only needs a default export with a `fetch` method, and the router module can provide that itself, so the demo no longer needs a separate entry file. `app/router.ts` adds `export default router` and the tasks run `deno serve app/router.ts`.
`deno check` with no arguments checks the whole project, so the typecheck task covers `app/data.ts` and `app/routes.ts` as well, not only what the router module imports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A router created with
createRouter()already exposes afetchmethod, which is exactly the shapeDeno.serveanddeno serveexpect. I have been running Remix 3 on Deno for a while now and it has been a really pleasant fit, so I would like to add a Deno demo next to the existing Bun and Node ones underpackages/fetch-router/demos/.It is the same blog application as the Node and Bun demos, so the three sit side by side and show that the router, middleware, and route helpers are runtime-agnostic. The difference is that on Deno there is no server entry point to write at all:
deno servedoes the rest.packages/fetch-router/demos/deno/with the same routes, actions, and in-memory data as the Bun demodeno servepicks up itsfetchmethod and Deno owns the listener, the port, and graceful shutdown onSIGINT/SIGTERMpublic/withstaticFiles()from@remix-run/static-middlewareinstead of the hand-rolled file handler in the Bun demo, which also exercises Deno'snode:fs/node:urlcompatibilitydeno.jsonsets"nodeModulesDir": "manual"so Deno resolves@remix-run/*from the pnpm workspace'snode_modules, and the tasks run with least-privilege permissions on port 44100A few notes for reviewers:
The demo intentionally defines no typecheck or test script in its package.json, so pnpm -r typecheck and pnpm test stay green on machines without Deno installed. This matches the existing packages/multipart-parser/demos/deno. Type checking is available through deno task typecheck.
@types/node is a dev dependency because Deno needs it present in node_modules to resolve the node type reference that comes in through the @remix-run/* sources.
The permissions are deliberately narrow: static imports need no read permission, so --allow-read=./public covers the only runtime filesystem access, and --allow-env is limited to the four variables logger() inspects for color detection through @remix-run/terminal. deno serve provides its own network access, so no --allow-net is needed.
Tested with Deno 2.9.4.