add reply to middlewareResponse

This commit is contained in:
HorizonCode 2023-05-12 11:56:48 +02:00
parent 301a6d2c3d
commit 1c668e5892
2 changed files with 6 additions and 4 deletions

View File

@ -4,7 +4,8 @@ import { HTTPServer } from "../mod.ts";
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}`);
const processTime = await done();
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)
.header("working", "true")
.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)
.type("application/json");

3
mod.ts
View File

@ -21,6 +21,7 @@ type RouteHandler = (
type RouteMiddlewareHandler = (
req: RouteRequest,
rep: RouteReply,
done: () => Promise<number[]>,
) => Promise<void>;
@ -124,7 +125,7 @@ export class HTTPServer {
resolveAction = resolve;
});
};
this.middlewareHandler(routeRequest, middlewarePromise);
this.middlewareHandler(routeRequest, routeReply, middlewarePromise);
}
if (this.staticServePath && filepath.startsWith(this.staticServePath)) {