[app] CalmRefresh: Register the worker in the app and offer the waiting version; e2e publishes a real second one
This commit is contained in:
+10
-4
@@ -19,7 +19,7 @@ import { fileURLToPath } from 'node:url';
|
||||
*/
|
||||
|
||||
export const BASE = process.env['ROSEA_BASE'] ?? '/Rosea/';
|
||||
const DIST = fileURLToPath(new URL('../apps/rosea/dist', import.meta.url));
|
||||
export const DIST = fileURLToPath(new URL('../apps/rosea/dist', import.meta.url));
|
||||
|
||||
const MIME: Record<string, string> = {
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
@@ -36,6 +36,8 @@ export interface StaticServer {
|
||||
readonly url: string;
|
||||
readonly origin: string;
|
||||
readonly close: () => Promise<void>;
|
||||
/** Serves another build from now on, at the same URL: a new version being published. */
|
||||
readonly serveFrom: (dir: string) => void;
|
||||
}
|
||||
|
||||
export async function startStaticServer(): Promise<StaticServer> {
|
||||
@@ -45,6 +47,7 @@ export async function startStaticServer(): Promise<StaticServer> {
|
||||
throw new Error(`No built app at ${DIST}. Run \`pnpm build\` first. (${String(error)})`);
|
||||
}
|
||||
|
||||
let root = DIST;
|
||||
const server: Server = createServer((req, res) => {
|
||||
const path = decodeURIComponent((req.url ?? '/').split('?')[0] ?? '/');
|
||||
|
||||
@@ -55,9 +58,9 @@ export async function startStaticServer(): Promise<StaticServer> {
|
||||
}
|
||||
|
||||
const rel = normalize(path.slice(BASE.length) || 'index.html');
|
||||
const file = join(DIST, rel);
|
||||
// Confine to DIST: a test server is still a server.
|
||||
if (!file.startsWith(DIST + sep) && file !== DIST) {
|
||||
const file = join(root, rel);
|
||||
// Confine to the served folder: a test server is still a server.
|
||||
if (!file.startsWith(root + sep) && file !== root) {
|
||||
res.writeHead(403).end();
|
||||
return;
|
||||
}
|
||||
@@ -90,6 +93,9 @@ export async function startStaticServer(): Promise<StaticServer> {
|
||||
return {
|
||||
origin,
|
||||
url: `${origin}${BASE}`,
|
||||
serveFrom: (dir) => {
|
||||
root = dir;
|
||||
},
|
||||
close: () =>
|
||||
new Promise<void>((resolve) => {
|
||||
server.closeAllConnections();
|
||||
|
||||
Reference in New Issue
Block a user