23 lines
685 B
JavaScript
23 lines
685 B
JavaScript
function toRouterPath(configuredPath, defaultApiPath) {
|
|
const fallback = String(defaultApiPath || '/').trim() || '/';
|
|
const raw = String(configuredPath || fallback).trim() || fallback;
|
|
|
|
let path = raw.startsWith('/') ? raw : `/${raw}`;
|
|
|
|
// Routers are mounted under /api in server.js, so strip an optional /api prefix.
|
|
if (path === '/api') path = '/';
|
|
if (path.startsWith('/api/')) path = path.slice(4);
|
|
|
|
if (path.length > 1) path = path.replace(/\/+$/, '');
|
|
return path || '/';
|
|
}
|
|
|
|
function getRouterPathFromApiEnv(envKey, defaultApiPath) {
|
|
return toRouterPath(process.env[envKey], defaultApiPath);
|
|
}
|
|
|
|
module.exports = {
|
|
toRouterPath,
|
|
getRouterPathFromApiEnv,
|
|
};
|