worker-tools / router Goto Github PK
View Code? Open in Web Editor NEWA router for Worker Runtimes such and Cloudflare Workers or Service Workers.
Home Page: https://workers.tools/router
A router for Worker Runtimes such and Cloudflare Workers or Service Workers.
Home Page: https://workers.tools/router
It'd be really helpful if the docs mentioned how to use env vars.
I can confirm that without this library, env.SOME_KEY
does logged, however, as soon as I export router
then the env
item in my handler callback doesn't have that value.
Thanks for an awesome library btw.
Currently it is not possible to reliably resolve full URL from a subrouter as subrouter ctx.match
is matched from a partial path provided in WorkerRouter.use
. The only way to resolve full URL within subrouters is to make assumptions about parent routes which goes against idea of composability.
It would be really useful to pass parent match to subrouters making it possible to reliably resolve full URL within a subrouter.
With Server-sent endpoints it is often the case that connection is closed before Deno flushes body stream. When that happens, following error is thrown:
Uncaught Http: connection closed before message completed
await requestEvent.respondWith(response);
^
at Object.respondWith (ext:deno_http/01_http.js:336:25)
at eventLoopTick (ext:core/01_core.js:188:13)
at async Server.#respond (https://deno.land/[email protected]/http/server.ts:311:7)
I tried to try/catch handler and listen to router 'error' handler but it looks like the error is thrown outside the context of the router.
Is it somehow possible to catch this error and conditionally silence it?
When request is made to a InnerRouter
mounted via RootRouter.use
, its middleware is ignored.
Example:
import { serve } from "https://deno.land/[email protected]/http/server.ts"
import * as shed from "https://raw.githubusercontent.com/worker-tools/shed/master/index.ts"
const InnerRouter = new shed.WorkerRouter((ax) => {
console.log("InnerRouter: middleware")
return ax
})
InnerRouter.get("/", () => shed.ok("inner"))
const RootRouter = new shed.WorkerRouter((ax) => {
console.log("RootRouter: middleware")
return ax
})
RootRouter.get("/", () => shed.ok("root"))
RootRouter.use("/inner*", InnerRouter)
await RootRouter.fetch(new Request("http://localhost/"))
await RootRouter.fetch(new Request("http://localhost/inner"))
Code above will print:
RootRouter: middleware
InnerRouter: middleware
It should print RootRouter: middleware
two times instead of one.
When request passes through a router, it should run its middleware, even when it's being forwarded to a sub-router.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.