sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
40 lines (39 loc) • 1.54 kB
JavaScript
function ensureTrailingSlash(path) {
return path.endsWith("/") ? path : `${path}/`;
}
function gracefulServerDeath(command, httpHost, httpPort, err) {
if (err.code === "EADDRINUSE")
throw new Error(`Port number is already in use, configure \`server.port\` in \`sanity.cli.js\` or pass \`--port <somePort>\` to \`sanity ${command}\``);
if (err.code === "EACCES") {
const help = httpPort < 1024 ? "port numbers below 1024 requires root privileges" : `do you have access to listen to the given host (${httpHost || "127.0.0.1"})?`;
throw new Error(`The studio server does not have access to listen to given port - ${help}`);
}
throw err;
}
function getSharedServerConfig({
flags,
workDir,
cliConfig
}) {
const env = process.env, httpHost = flags.host || env.SANITY_STUDIO_SERVER_HOSTNAME || cliConfig?.server?.hostname || "localhost", httpPort = toInt(flags.port || env.SANITY_STUDIO_SERVER_PORT || cliConfig?.server?.port, 3333), basePath = ensureTrailingSlash(env.SANITY_STUDIO_BASEPATH ?? (cliConfig?.project?.basePath || "/")), isApp = cliConfig && "app" in cliConfig, entry = cliConfig?.app?.entry;
return {
cwd: workDir,
httpPort,
httpHost,
basePath,
vite: cliConfig?.vite,
entry,
isApp
};
}
function toInt(value, defaultValue) {
if (typeof value > "u")
return defaultValue;
const intVal = parseInt(`${value}`, 10);
return Number.isFinite(intVal) ? intVal : defaultValue;
}
export {
getSharedServerConfig,
gracefulServerDeath
};
//# sourceMappingURL=servers.js.map