1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/config.js
Jerome Fitzgerald c92bc858f7 [refactor] poweredByHeader (#3716) (#3807)
This reverts `fb7c862` per @timneutkens

- Removes the errors/*.md associated
- Puts back `poweredByHeader` for `next.config.js`
- Reincorporates test:

X-Powered-By header
    ✓ should set it by default (3ms)
    ✓ should not set it when poweredByHeader==false (5ms)

Also tested with `yarn link` and verified.
2018-02-14 18:02:48 +01:00

46 lines
1.1 KiB
JavaScript

import findUp from 'find-up'
const cache = new Map()
const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
pageExtensions: ['jsx', 'js'] // jsx before js because otherwise regex matching will match js first
}
export default function getConfig (dir, customConfig) {
if (!cache.has(dir)) {
cache.set(dir, loadConfig(dir, customConfig))
}
return cache.get(dir)
}
function loadConfig (dir, customConfig) {
if (customConfig && typeof customConfig === 'object') {
customConfig.configOrigin = 'server'
return withDefaults(customConfig)
}
const path = findUp.sync('next.config.js', {
cwd: dir
})
let userConfig = {}
if (path && path.length) {
const userConfigModule = require(path)
userConfig = userConfigModule.default || userConfigModule
userConfig.configOrigin = 'next.config.js'
}
return withDefaults(userConfig)
}
function withDefaults (config) {
return Object.assign({}, defaultConfig, config)
}