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

Merge pull request #3189 from logto-io/gao-add-etag-for-spa

refactor(cloud): set ETag for SPA
This commit is contained in:
Gao Sun 2023-02-23 16:42:59 +08:00 committed by GitHub
commit fe1fa2a7bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 7 deletions

View file

@ -10,7 +10,7 @@
"dev": "pnpm -r prepack && pnpm start:dev", "dev": "pnpm -r prepack && pnpm start:dev",
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud", "dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
"start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter=!@logto/cloud dev", "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": "cd packages/core && NODE_ENV=production node .",
"start:cloud": "cd packages/cloud && NODE_ENV=production node .", "start:cloud": "cd packages/cloud && NODE_ENV=production node .",
"cli": "logto", "cli": "logto",

View file

@ -73,6 +73,7 @@ export default function withSpa<InputContext extends RequestContext>({
'Content-Type': mime.lookup(pathLike), 'Content-Type': mime.lookup(pathLike),
'Last-Modified': stat.mtime.toUTCString(), 'Last-Modified': stat.mtime.toUTCString(),
'Cache-Control': `max-age=${maxAge}`, 'Cache-Control': `max-age=${maxAge}`,
ETag: `"${stat.size.toString(16)}-${stat.mtimeMs.toString(16)}"`,
}, },
stream: createReadStream(pathLike), stream: createReadStream(pathLike),
status: 200, 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) => { const tryStat = async (pathLike: string) => {
try { try {
const stat = await fs.stat(pathLike); const stat = await fs.stat(pathLike);