This commit is contained in:
miles committed 2026-11-09 17:25:42 -06:00
1 parent c250653961
commit f26fdd9d07
18 files changed
+493 -83

No files matched your search

+1
View File
@@ -67,6 +67,7 @@ export function corsFor(origin, allowedOrigins) {
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Expose-Headers': 'Retry-After',
'Access-Control-Max-Age': '600',
Vary: 'Origin'
};
+11 -7
View File
@@ -68,12 +68,16 @@ function cacheControl(file) {
: 'public, max-age=3600';
}
export async function resolveStaticPath(root, rawPathname) {
export async function resolveStaticPath(root, rawPathname, { decodedPath = false } = {}) {
let pathname;
try {
pathname = decodeURIComponent(rawPathname);
} catch {
return { error: 400 };
if (decodedPath) {
pathname = rawPathname;
} else {
try {
pathname = decodeURIComponent(rawPathname);
} catch {
return { error: 400 };
}
}
if (!pathname.startsWith('/') || pathname.includes('\\') || pathname.includes('\0')) {
return { error: 400 };
@@ -165,8 +169,8 @@ export async function sendFile(req, res, file, stat, { status = 200, cache = nul
fs.createReadStream(file).pipe(res);
}
export async function serveStatic(req, res, { root, pathname, notFoundFile = null, cache = null }) {
const result = await resolveStaticPath(root, pathname);
export async function serveStatic(req, res, { root, pathname, notFoundFile = null, cache = null, decodedPath = false }) {
const result = await resolveStaticPath(root, pathname, { decodedPath });
if (result.error === 404) {
if (notFoundFile) {
try {