UNPKG

@astrojs/node

Version:
22 lines (21 loc) 877 B
import path from "node:path"; import url from "node:url"; import { appendForwardSlash } from "@astrojs/internal-helpers/path"; const STATIC_HEADERS_FILE = "_experimentalHeaders.json"; function resolveClientDir(options) { const clientURLRaw = new URL(options.client); const serverURLRaw = new URL(options.server); const rel = path.relative(url.fileURLToPath(serverURLRaw), url.fileURLToPath(clientURLRaw)); const serverFolder = path.basename(options.server); let serverEntryFolderURL = path.dirname(import.meta.url); while (!serverEntryFolderURL.endsWith(serverFolder)) { serverEntryFolderURL = path.dirname(serverEntryFolderURL); } const serverEntryURL = serverEntryFolderURL + "/entry.mjs"; const clientURL = new URL(appendForwardSlash(rel), serverEntryURL); return url.fileURLToPath(clientURL); } export { STATIC_HEADERS_FILE, resolveClientDir };