Consider base path in set-routes-manifest
This commit is contained in:
@@ -7,8 +7,10 @@ const routesManifestPath = path.resolve(__dirname, '../.next/routes-manifest.jso
|
|||||||
const originalPath = path.resolve(__dirname, '../.next/routes-manifest-orig.json');
|
const originalPath = path.resolve(__dirname, '../.next/routes-manifest-orig.json');
|
||||||
const originalManifest = require(originalPath);
|
const originalManifest = require(originalPath);
|
||||||
|
|
||||||
const API_PATH = '/api/:path*';
|
const basePath = originalManifest.basePath;
|
||||||
const TRACKER_SCRIPT = '/script.js';
|
|
||||||
|
const API_PATH = basePath + '/api/:path*';
|
||||||
|
const TRACKER_SCRIPT = basePath + '/script.js';
|
||||||
|
|
||||||
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
|
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
|
||||||
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
@@ -20,14 +22,16 @@ if (collectApiEndpoint) {
|
|||||||
const apiRoute = originalManifest.headers.find(route => route.source === API_PATH);
|
const apiRoute = originalManifest.headers.find(route => route.source === API_PATH);
|
||||||
const routeRegex = new RegExp(apiRoute.regex);
|
const routeRegex = new RegExp(apiRoute.regex);
|
||||||
|
|
||||||
|
const normalizedSource = basePath + collectApiEndpoint;
|
||||||
|
|
||||||
rewrites.push({
|
rewrites.push({
|
||||||
source: collectApiEndpoint,
|
source: normalizedSource,
|
||||||
destination: '/api/send',
|
destination: basePath + '/api/send',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!routeRegex.test(collectApiEndpoint)) {
|
if (!routeRegex.test(normalizedSource)) {
|
||||||
headers.push({
|
headers.push({
|
||||||
source: collectApiEndpoint,
|
source: normalizedSource,
|
||||||
headers: apiRoute.headers,
|
headers: apiRoute.headers,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -40,7 +44,7 @@ if (trackerScriptName) {
|
|||||||
|
|
||||||
if (names) {
|
if (names) {
|
||||||
names.forEach(name => {
|
names.forEach(name => {
|
||||||
const normalizedSource = `/${name.replace(/^\/+/, '')}`;
|
const normalizedSource = `${basePath}/${name.replace(/^\/+/, '')}`;
|
||||||
|
|
||||||
rewrites.push({
|
rewrites.push({
|
||||||
source: normalizedSource,
|
source: normalizedSource,
|
||||||
|
|||||||
Reference in New Issue
Block a user