@serverless-stack/nextjs-lambda
Version:
Provides handlers that can be used in CloudFront Lambda@Edge to deploy next.js applications to the edge
46 lines (45 loc) • 2.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTrailingSlashRedirect = void 0;
function isTrailingSlashRedirect(redirect, basePath) {
if (redirect.internal === true) {
return true;
}
if (basePath !== "") {
return ((redirect.statusCode === 308 &&
((redirect.source === `${basePath}` &&
redirect.destination === `${basePath}/`) ||
(redirect.source === `${basePath}/` &&
redirect.destination === `${basePath}`) ||
(redirect.source === `${basePath}/:path+/` &&
redirect.destination === `${basePath}/:path+`) ||
(redirect.source === `${basePath}/:file((?:[^/]+/)*[^/]+\\.\\w+)/` &&
redirect.destination === `${basePath}/:file`) ||
(redirect.source === `${basePath}/:notfile((?:[^/]+/)*[^/\\.]+)` &&
redirect.destination === `${basePath}/:notfile/`))) ||
(redirect.source ===
`${basePath}/:file((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+)/` &&
redirect.destination === `${basePath}/:file`) ||
(redirect.source ===
`${basePath}/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)` &&
redirect.destination === `${basePath}/:notfile/`));
}
else {
return ((redirect.statusCode === 308 &&
((redirect.source === "/:path+/" &&
redirect.destination === "/:path+") ||
(redirect.source === "/:path+" &&
redirect.destination === "/:path+/") ||
(redirect.source === "/:file((?:[^/]+/)*[^/]+\\.\\w+)/" &&
redirect.destination === "/:file") ||
(redirect.source === "/:notfile((?:[^/]+/)*[^/\\.]+)" &&
redirect.destination === "/:notfile/"))) ||
(redirect.source ===
"/:file((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+)/" &&
redirect.destination === "/:file") ||
(redirect.source ===
"/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)" &&
redirect.destination === "/:notfile/"));
}
}
exports.isTrailingSlashRedirect = isTrailingSlashRedirect;
;