exports types
This commit is contained in:
34
router.ts
34
router.ts
@@ -1,34 +1,4 @@
|
||||
interface RouterContext {
|
||||
url: URL;
|
||||
params: Record<string, string | undefined>;
|
||||
state: Record<string, unknown>;
|
||||
pattern: URLPattern;
|
||||
request: Request;
|
||||
}
|
||||
|
||||
type Handler = (req: Request, ctx: RouterContext) => Promise<Response> | Response;
|
||||
type Middleware = (ctx: RouterContext, next: () => Promise<Response>) => Promise<Response>;
|
||||
|
||||
interface RouteConfig {
|
||||
pattern: URLPattern;
|
||||
handlers: { [method: string]: Handler };
|
||||
}
|
||||
|
||||
interface MiddlewareConfig {
|
||||
pattern: URLPattern;
|
||||
handler: Middleware;
|
||||
// Add path for sorting
|
||||
path: string;
|
||||
}
|
||||
|
||||
interface RouteConfigurator {
|
||||
get(handler: Handler): RouteConfigurator;
|
||||
post(handler: Handler): RouteConfigurator;
|
||||
put(handler: Handler): RouteConfigurator;
|
||||
delete(handler: Handler): RouteConfigurator;
|
||||
patch(handler: Handler): RouteConfigurator;
|
||||
options(handler: Handler): RouteConfigurator;
|
||||
}
|
||||
import type { Handler, Middleware, MiddlewareConfig, RouteConfig, RouteConfigurator, RouterContext } from "./types.ts";
|
||||
|
||||
/**
|
||||
* A simple router for Deno
|
||||
@@ -327,7 +297,7 @@ if (import.meta.main) {
|
||||
console.log('Starting server...');
|
||||
const router = new Router();
|
||||
router.route('/users')
|
||||
.get((ctx) => {
|
||||
.get((_ctx) => {
|
||||
return new Response('GET /users');
|
||||
})
|
||||
// .post((ctx) => {
|
||||
|
Reference in New Issue
Block a user