0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(cloud): set etag for SPA

This commit is contained in:
Gao Sun 2023-02-23 12:38:18 +08:00
parent 720d1ecb33
commit 02db28fc35
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 2 additions and 7 deletions

View file

@ -10,7 +10,7 @@
"dev": "pnpm -r prepack && pnpm start:dev",
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
"start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter=!@logto/cloud dev",
"start:dev:cloud": "CONSOLE_PUBLIC_URL=/ pnpm -r --parallel --filter=!@logto/integration-tests dev",
"start:dev:cloud": "CONSOLE_PUBLIC_URL=/ IS_CLOUD=1 pnpm -r --parallel --filter=!@logto/integration-tests dev",
"start": "cd packages/core && NODE_ENV=production node .",
"start:cloud": "cd packages/cloud && NODE_ENV=production node .",
"cli": "logto",

View file

@ -73,6 +73,7 @@ export default function withSpa<InputContext extends RequestContext>({
'Content-Type': mime.lookup(pathLike),
'Last-Modified': stat.mtime.toUTCString(),
'Cache-Control': `max-age=${maxAge}`,
ETag: `"${stat.size.toString(16)}-${stat.mtimeMs.toString(16)}"`,
},
stream: createReadStream(pathLike),
status: 200,
@ -80,12 +81,6 @@ export default function withSpa<InputContext extends RequestContext>({
};
}
const normalize = (pathLike: string) => {
const value = path.normalize(pathLike);
return value.length > 1 && value.endsWith('/') ? value.slice(0, -1) : value;
};
const tryStat = async (pathLike: string) => {
try {
const stat = await fs.stat(pathLike);