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
45 lines (44 loc) • 1.78 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
}) {
var _a, _b, _c, _d;
const env = process.env, httpHost = flags.host || env.SANITY_STUDIO_SERVER_HOSTNAME || ((_a = cliConfig == null ? void 0 : cliConfig.server) == null ? void 0 : _a.hostname) || "localhost", httpPort = toInt(
flags.port || env.SANITY_STUDIO_SERVER_PORT || ((_b = cliConfig == null ? void 0 : cliConfig.server) == null ? void 0 : _b.port),
3333
), basePath = ensureTrailingSlash(
(_d = env.SANITY_STUDIO_BASEPATH) != null ? _d : ((_c = cliConfig == null ? void 0 : cliConfig.project) == null ? void 0 : _c.basePath) || "/"
);
return {
cwd: workDir,
httpPort,
httpHost,
basePath,
vite: cliConfig == null ? void 0 : cliConfig.vite
};
}
function toInt(value, defaultValue) {
if (typeof value > "u")
return defaultValue;
const intVal = parseInt(`${value}`, 10);
return Number.isFinite(intVal) ? intVal : defaultValue;
}
exports.getSharedServerConfig = getSharedServerConfig;
exports.gracefulServerDeath = gracefulServerDeath;
//# sourceMappingURL=servers.js.map