import { KeyworkRouter } from "https://deno.land/x/keywork@v6.2.1/router/mod.ts";
Combines additional routers and their respective route handlers to this router.
Route handlers are matched in the order of their declaration:
const app = new RequestRouter()
app.get('/foo', ({request}) => {
return new Response('This handler got here first!')
})
app.get('/foo', ({request}) => {
return new Response('This handler won't be called!')
})
However, if you want another router to act as middleware,
Call use
before defining your route handlers:
const authenticationRouter = new RequestRouter()
authenticationRouter.all('*', ({request, next}) => {
if (!hasAuthCookie(request)) {
return new KeyworkResourceError(401, "You need to be signed in to do that!")
}
// Pass the request along to the next matching route handler.
return next()
})
const app = new RequestRouter()
app.use('/', authenticationRouter)
app.get('/user/profile', ({request}) => {
return new Response("Some user only content.")
})