add object returner support
This commit is contained in:
parent
bf454f83b8
commit
ab10ab7091
|
@ -9,12 +9,12 @@ httpServer.error((req, _rep) => {
|
||||||
code: Status.NotFound,
|
code: Status.NotFound,
|
||||||
message: "Route not found!",
|
message: "Route not found!",
|
||||||
path: req.path,
|
path: req.path,
|
||||||
url: req.url
|
url: req.url,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
httpServer.add("GET", "/", (req, rep) => {
|
httpServer.add("GET", "/", (req, rep) => {
|
||||||
rep.status(Status.Teapot)
|
rep.status(Status.Teapot)
|
||||||
|
@ -24,14 +24,10 @@ httpServer.add("GET", "/", (req, rep) => {
|
||||||
|
|
||||||
console.log(req.cookie("working"));
|
console.log(req.cookie("working"));
|
||||||
|
|
||||||
return JSON.stringify(
|
return {
|
||||||
{
|
|
||||||
code: Status.Teapot,
|
code: Status.Teapot,
|
||||||
message: "Hello World!",
|
message: "Hello World!",
|
||||||
},
|
};
|
||||||
null,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.add("GET", "/api/user/:userId", (req, rep) => {
|
httpServer.add("GET", "/api/user/:userId", (req, rep) => {
|
||||||
|
|
7
mod.ts
7
mod.ts
|
@ -117,10 +117,15 @@ export class HTTPServer {
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (route) {
|
if (route) {
|
||||||
const handler = await route.handler(
|
let handler = await route.handler(
|
||||||
routeRequest,
|
routeRequest,
|
||||||
routeReply,
|
routeReply,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (typeof (handler) == "object") {
|
||||||
|
handler = JSON.stringify(handler, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
await requestEvent.respondWith(
|
await requestEvent.respondWith(
|
||||||
new Response(handler as string, {
|
new Response(handler as string, {
|
||||||
status: routeReply.statusCode,
|
status: routeReply.statusCode,
|
||||||
|
|
Reference in New Issue
Block a user