add reply to middlewareResponse
This commit is contained in:
parent
301a6d2c3d
commit
1c668e5892
|
@ -4,7 +4,8 @@ import { HTTPServer } from "../mod.ts";
|
||||||
|
|
||||||
const httpServer = new HTTPServer();
|
const httpServer = new HTTPServer();
|
||||||
|
|
||||||
httpServer.middleware(async (req, done) => {
|
httpServer.middleware(async (req, rep, done) => {
|
||||||
|
rep.header("Access-Control-Allow-Origin", "*");
|
||||||
console.log(`${req.method} - ${req.remoteIpAddr} - ${req.path}`);
|
console.log(`${req.method} - ${req.remoteIpAddr} - ${req.path}`);
|
||||||
const processTime = await done();
|
const processTime = await done();
|
||||||
console.log(`Processed in ${prettyTime(processTime)}`);
|
console.log(`Processed in ${prettyTime(processTime)}`);
|
||||||
|
@ -23,7 +24,7 @@ httpServer.error((req, _rep) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.add("GET", "/", (req, rep) => {
|
httpServer.get("/", (req, rep) => {
|
||||||
rep.status(Status.Teapot)
|
rep.status(Status.Teapot)
|
||||||
.header("working", "true")
|
.header("working", "true")
|
||||||
.type("application/json")
|
.type("application/json")
|
||||||
|
@ -37,7 +38,7 @@ httpServer.add("GET", "/", (req, rep) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.add("GET", "/api/user/:userId", (req, rep) => {
|
httpServer.get("/api/user/:userId", (req, rep) => {
|
||||||
rep.status(Status.Teapot)
|
rep.status(Status.Teapot)
|
||||||
.type("application/json");
|
.type("application/json");
|
||||||
|
|
||||||
|
|
3
mod.ts
3
mod.ts
|
@ -21,6 +21,7 @@ type RouteHandler = (
|
||||||
|
|
||||||
type RouteMiddlewareHandler = (
|
type RouteMiddlewareHandler = (
|
||||||
req: RouteRequest,
|
req: RouteRequest,
|
||||||
|
rep: RouteReply,
|
||||||
done: () => Promise<number[]>,
|
done: () => Promise<number[]>,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ export class HTTPServer {
|
||||||
resolveAction = resolve;
|
resolveAction = resolve;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
this.middlewareHandler(routeRequest, middlewarePromise);
|
this.middlewareHandler(routeRequest, routeReply, middlewarePromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.staticServePath && filepath.startsWith(this.staticServePath)) {
|
if (this.staticServePath && filepath.startsWith(this.staticServePath)) {
|
||||||
|
|
Reference in New Issue
Block a user