-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
24 lines (19 loc) · 852 Bytes
/
Copy pathproxy.js
File metadata and controls
24 lines (19 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { NextResponse } from "next/server";
const FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" fill="#fbfaf6"/><text x="7" y="22" font-family="monospace" font-size="17" fill="#0a0a0a">h</text></svg>`;
export function proxy(request) {
const { pathname, searchParams } = request.nextUrl;
const post = searchParams.get("post");
if (post && post.endsWith(".md")) {
const slug = post.replace(/\.md$/, "");
if (!/^[\w-]+$/.test(slug)) return;
return NextResponse.rewrite(new URL(`/md/${slug}`, request.url));
}
if (pathname === "/favicon.ico") {
return new NextResponse(FAVICON_SVG, {
headers: { "Content-Type": "image/svg+xml", "Cache-Control": "public, max-age=31536000, immutable" },
});
}
}
export const config = {
matcher: ["/", "/favicon.ico"],
};