UNPKG

@sls-next/core

Version:
27 lines (26 loc) 927 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalise = void 0; const normalise = (uri, routesManifest) => { const { basePath } = routesManifest; if (basePath) { if (uri.startsWith(basePath)) { uri = uri.slice(basePath.length); } else { // basePath set but URI does not start with basePath, return original path with special flag indicating missing expected base path // but basePath is expected return { normalisedUri: uri, missingExpectedBasePath: true }; } } // Remove trailing slash for all paths if (uri.endsWith("/")) { uri = uri.slice(0, -1); } // Empty path should be normalised to "/" as there is no Next.js route for "" return { normalisedUri: uri === "" ? "/" : uri, missingExpectedBasePath: false }; }; exports.normalise = normalise;