Skip to content

Commit 3efa580

Browse files
feat: add redirects for DSG pages (#102)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent babca94 commit 3efa580

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/gatsby-node.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }, userPluginOpt
6868
`[gatsby-plugin-netlify] Your site has ${pages.size} pages, which means that the generated headers file could become very large. Consider disabling "mergeCachingHeaders" and "mergeLinkHeaders" in your plugin config`,
6969
)
7070
}
71-
reporter.info(`[gatsby-plugin-netlify] Creating SSR redirects...`)
71+
reporter.info(`[gatsby-plugin-netlify] Creating SSR/DSG redirects...`)
7272

7373
let count = 0
7474
const rewrites = []
@@ -77,20 +77,19 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }, userPluginOpt
7777

7878
;[...pages.values()].forEach((page) => {
7979
const { mode, matchPath, path } = page
80-
if (mode === 'SSR' || mode === 'DSG') {
80+
if (mode === `SSR` || mode === `DSG`) {
8181
needsFunctions = true
82-
}
83-
if (mode === `SSR`) {
8482
const fromPath = matchPath ?? path
83+
const toPath = mode === `SSR` ? `/.netlify/functions/__ssr` : `/.netlify/functions/__dsg`
8584
count++
8685
rewrites.push(
8786
{
8887
fromPath,
89-
toPath: `/.netlify/functions/__ssr`,
88+
toPath,
9089
},
9190
{
9291
fromPath: generatePageDataPath(`/`, fromPath),
93-
toPath: `/.netlify/functions/__ssr`,
92+
toPath,
9493
},
9594
)
9695
}
@@ -101,11 +100,11 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }, userPluginOpt
101100
})
102101
}
103102
})
104-
reporter.info(`[gatsby-plugin-netlify] Created ${count} SSR redirect${count === 1 ? `` : `s`}...`)
103+
reporter.info(`[gatsby-plugin-netlify] Created ${count} SSR/DSG redirect${count === 1 ? `` : `s`}...`)
105104

106105
if (!needsFunctions) {
107106
reporter.info(`[gatsby-plugin-netlify] No Netlify functions needed. Skipping...`)
108-
await fs.writeFile(join(program.directory, `.cache`, `.nf-skip-gatsby-functions`), '')
107+
await fs.writeFile(join(program.directory, `.cache`, `.nf-skip-gatsby-functions`), ``)
109108
}
110109

111110
await Promise.all([

0 commit comments

Comments
 (0)