mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-28 05:54:43 -04:00
Refactor handling of environment variables (#2303)
* Refactor environment variables Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
e412115a78
commit
39a4125cb0
85 changed files with 624 additions and 461 deletions
|
@ -3,47 +3,27 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
const { isMockMode, isTestMode } = require('./src/utils/test-modes')
|
||||
const path = require('path')
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
enabled: process.env.ANALYZE === 'true'
|
||||
})
|
||||
|
||||
//TODO: [mrdrogdrog] The following function and two constants already exist in typescript code.
|
||||
// However, this file must be a js file and therefore can't access the ts function.
|
||||
// I have no idea how to resolve this redundancy without extracting it into a node module.
|
||||
const isPositiveAnswer = (value) => {
|
||||
const lowerValue = value.toLowerCase()
|
||||
return lowerValue === 'yes' || lowerValue === '1' || lowerValue === 'true'
|
||||
}
|
||||
|
||||
const isTestMode = !!process.env.NEXT_PUBLIC_TEST_MODE && isPositiveAnswer(process.env.NEXT_PUBLIC_TEST_MODE)
|
||||
|
||||
const isMockMode = !!process.env.NEXT_PUBLIC_USE_MOCK_API && isPositiveAnswer(process.env.NEXT_PUBLIC_USE_MOCK_API)
|
||||
|
||||
console.log('Node env is', process.env.NODE_ENV)
|
||||
console.log('Node environment is', process.env.NODE_ENV)
|
||||
|
||||
if (isMockMode) {
|
||||
console.log('Uses mock API')
|
||||
} else if (!!process.env.NEXT_PUBLIC_BACKEND_BASE_URL) {
|
||||
console.log('Backend base url is', process.env.NEXT_PUBLIC_BACKEND_BASE_URL)
|
||||
} else {
|
||||
console.error(`==============
|
||||
Neither NEXT_PUBLIC_USE_MOCK_API or NEXT_PUBLIC_BACKEND_BASE_URL is set.
|
||||
If you want to create a production build we suggest that you set a backend url with NEXT_PUBLIC_BACKEND_BASE_URL.
|
||||
If you want to create a build that uses the mock api then use build:mock instead or set NEXT_PUBLIC_USE_MOCK_API to "true".
|
||||
==============`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!!process.env.NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG) {
|
||||
console.warn(
|
||||
'You have set NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG. This flag is ONLY for testing purposes and will decrease the security of the editor if used in production!'
|
||||
)
|
||||
console.log('Use mock API')
|
||||
}
|
||||
|
||||
if (isTestMode) {
|
||||
console.warn(`This build runs in test mode. This means:
|
||||
- no sandboxed iframe
|
||||
- Additional data-attributes for e2e tests added to DOM`)
|
||||
- Additional data-attributes for e2e tests added to DOM
|
||||
- Editor and renderer are running on the same origin`)
|
||||
}
|
||||
|
||||
if (!!isMockMode) {
|
||||
if (isMockMode) {
|
||||
console.warn(`This build runs in mock mode. This means:
|
||||
- No real data. All API responses are mocked
|
||||
- No persistent data
|
||||
|
@ -51,12 +31,6 @@ if (!!isMockMode) {
|
|||
`)
|
||||
}
|
||||
|
||||
const path = require('path')
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
enabled: process.env.ANALYZE === 'true'
|
||||
})
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const rawNextConfig = {
|
||||
webpack: (config) => {
|
||||
|
@ -111,9 +85,8 @@ const rawNextConfig = {
|
|||
}
|
||||
])
|
||||
},
|
||||
output: 'standalone',
|
||||
output: 'standalone'
|
||||
}
|
||||
|
||||
const completeNextConfig = withBundleAnalyzer(rawNextConfig)
|
||||
|
||||
module.exports = completeNextConfig
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue