-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathredirects.js
39 lines (30 loc) · 1.06 KB
/
redirects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { join } = require('path')
const slash = require('slash')
const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
const asyncForEach = require('../../helpers/asyncForEach')
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
const getPages = require('./pages')
const getRedirects = async () => {
const redirects = []
const pages = await getPages()
await asyncForEach(pages, async ({ route, dataRoute }) => {
const relativePath = getFilePathForRoute(route, 'js')
const filePath = slash(join('pages', relativePath))
const functionName = getNetlifyFunctionName(filePath)
const target = `/.netlify/functions/${functionName}`
await addLocaleRedirects(redirects, route, target)
// Add one redirect for the page
redirects.push({
route,
target,
})
// Add one redirect for the data route
redirects.push({
route: dataRoute,
target,
})
})
return redirects
}
module.exports = getRedirects