INNER CODE UNIT · TypeScript
validateOrigin
im4codes/imcodes · server/src/index.ts:506
function validateOrigin(origin: string, env: Env): boolean {
// Allow Capacitor native WebView origins (matches CORS middleware)
const nativeOrigins = ['capacitor://localhost', 'https://localhost', 'http://localhost'];
if (nativeOrigins.includes(origin)) return true;
if (!env.ALLOWED_ORIGINS) return env.NODE_ENV === 'development';
return env.ALLOWED_ORIGINS.split(',').map((s) => s.trim()).includes(origin);
}
// ── Preview WebSocket upgrade handler ─────────────────────────────────────────
async function handlePreviewWsUpgrade(
serverId: string,
previewId: string,
rawPath: string,
req: IncomingMessage,
socket: import('node:stream').Duplex,
head: Buffer,
url: URL,