Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/helpers/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const { readJSON } = require('fs-extra')
const { readJSON, existsSync } = require('fs-extra')
const { join, dirname, relative } = require('pathe')
const slash = require('slash')

Expand Down Expand Up @@ -79,14 +79,29 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
if (i18n) {
netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 })
}

const staticManifest = join(netlifyConfig.build.publish, 'static-manifest.json')
if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES && existsSync(staticManifest)) {
// Static page files need to have a forced redirect for preview mode. Otherwise it's non-forced
const staticFiles = await readJSON(staticManifest)
netlifyConfig.redirects.push(
...staticFiles.map((file) => ({
from: `${basePath}/${file}`,
to: HANDLER_FUNCTION_PATH,
status: 200,
force: true,
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
})),
)
}

// This is only used in prod, so dev uses `next dev` directly
netlifyConfig.redirects.push(
{ from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 },
{
from: `${basePath}/*`,
to: HANDLER_FUNCTION_PATH,
status: 200,
force: true,
conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] },
},
...redirects.map((redirect) => ({
Expand Down
1 change: 0 additions & 1 deletion test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Array [
"__next_preview_data",
],
},
"force": true,
"from": "/*",
"status": 200,
"to": "/.netlify/functions/___netlify-handler",
Expand Down