mdoTomofumi Chiba
1/13/2023, 11:48:42 AM

Fresh で SEO 的に 500 を 503 で偽る方法こんな感じかなぁ
routes/_middleware.ts

import { MiddlewareHandlerContext } from "$fresh/server.ts";

export async function handler(
  _req: Request,
  ctx: MiddlewareHandlerContext,
) {
  const resp = await ctx.next();
  if (resp.status === 500) {
    const contentType = resp.headers.get("content-type") || "text/plain";
    return new Response("503 Service Unavailable", {
      status: 503,
      headers: { "content-type": contentType },
    });
  }
  return resp;
}
TweetLike