-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathsetup.js
29 lines (22 loc) · 1015 Bytes
/
setup.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
const { join } = require('path')
const slash = require('slash')
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
const { logTitle } = require('../../helpers/logger')
const getPages = require('./pages')
// Create a Netlify Function for every page with getStaticProps and fallback
const setup = async (functionsPath) => {
logTitle('💫 Setting up pages with getStaticProps and fallback: true', 'as Netlify Functions in', functionsPath)
const pages = await getPages()
// Create Netlify Function for every page
return pages.reduce((jobs, { route }) => {
const relativePath = getFilePathForRoute(route, 'js')
const filePath = slash(join('pages', relativePath))
// Need two different functions - one ODB for normal pages, one standard for preview mode
return [
...jobs,
{ type: 'function', filePath, functionsPath, isODB: true },
{ type: 'function', filePath, functionsPath, forFallbackPreviewMode: true },
]
}, [])
}
module.exports = setup