Files
hyperframes/packages/inspector/src/pageServer.ts
T
Michael Wang 014326b40b fix: every composition file server refuses credential and tool-state files (#7889)
* wip: paused before review

* test: cover credential files on the preview routes and the deploy notice

* refactor: name the inspector's file lookup for what it serves

* fix(cli): a link to a private file outside the project keeps its own left-out reason

* fix: escape the upload notice and skip private files from old manifests
2026-11-16 01:42:08 +00:00

32 lines
1.0 KiB
TypeScript

import type { Server } from "node:http";
import { realpathSync } from "node:fs";
import { resolve, sep } from "node:path";
import { isPrivateFileUnder, isStudioPrivatePath } from "../../core/src/safePath";
export function closeServer(server: Server): Promise<void> {
const closed = new Promise<void>((done) => server.close(() => done()));
server.closeAllConnections();
server.removeAllListeners("request");
return closed;
}
export function isLoopbackHost(host: string | undefined): boolean {
if (!host) return true;
const name = host
.replace(/:\d+$/, "")
.replace(/^\[|\]$/g, "")
.toLowerCase();
return name === "127.0.0.1" || name === "localhost" || name === "::1";
}
export function servableProjectFile(project: string, urlPath: string): string | null {
const requested = resolve(project, `.${urlPath}`);
if (isPrivateFileUnder(project, requested, isStudioPrivatePath)) return null;
try {
const file = realpathSync(requested);
return file.startsWith(project + sep) ? file : null;
} catch {
return null;
}
}