Git Product home page Git Product logo

router's People

Contributors

qwtel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

router's Issues

Unsure how to handle env variables

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.

Pass base URL to subrouter

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.

Handling uncaught HTTP exceptions

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?

Sub-router ignores parent router middleware

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.