CentralBackend/utils/apiPath.js
DeathKaioken 918deb2b69 zua
Co-authored-by: Copilot <copilot@github.com>
2026-05-03 23:46:08 +02:00

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,
};