refactor: use named status codes from std internally (#417)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
ba20756c17
commit
1dc1f87fc3
@@ -4,6 +4,7 @@ import {
|
||||
fromFileUrl,
|
||||
RequestHandler,
|
||||
router,
|
||||
Status,
|
||||
toFileUrl,
|
||||
typeByExtension,
|
||||
walk,
|
||||
@@ -32,7 +33,6 @@ import {
|
||||
import { render as internalRender } from "./render.tsx";
|
||||
import { ContentSecurityPolicyDirectives, SELF } from "../runtime/csp.ts";
|
||||
import { ASSET_CACHE_BUST_KEY, INTERNAL_PREFIX } from "../runtime/utils.ts";
|
||||
|
||||
interface RouterState {
|
||||
state: Record<string, unknown>;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ export class ServerContext {
|
||||
const url = new URL(req.url);
|
||||
if (url.pathname.length > 1 && url.pathname.endsWith("/")) {
|
||||
url.pathname = url.pathname.slice(0, -1);
|
||||
return Response.redirect(url.href, 307);
|
||||
return Response.redirect(url.href, Status.TemporaryRedirect);
|
||||
}
|
||||
return withMiddlewares(req, connInfo, inner);
|
||||
};
|
||||
@@ -449,7 +449,7 @@ export class ServerContext {
|
||||
};
|
||||
|
||||
for (const route of this.#routes) {
|
||||
const createRender = genRender(route, 200);
|
||||
const createRender = genRender(route, Status.OK);
|
||||
if (typeof route.handler === "function") {
|
||||
routes[route.pattern] = (req, ctx, params) =>
|
||||
(route.handler as Handler)(req, {
|
||||
@@ -469,7 +469,7 @@ export class ServerContext {
|
||||
}
|
||||
}
|
||||
|
||||
const unknownHandlerRender = genRender(this.#notFound, 404);
|
||||
const unknownHandlerRender = genRender(this.#notFound, Status.NotFound);
|
||||
const unknownHandler: router.Handler<RouterState> = (
|
||||
req,
|
||||
ctx,
|
||||
@@ -482,7 +482,10 @@ export class ServerContext {
|
||||
},
|
||||
);
|
||||
|
||||
const errorHandlerRender = genRender(this.#error, 500);
|
||||
const errorHandlerRender = genRender(
|
||||
this.#error,
|
||||
Status.InternalServerError,
|
||||
);
|
||||
const errorHandler: router.ErrorHandler<RouterState> = (
|
||||
req,
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user