-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adds write config file on startup
- Loading branch information
Russell Green
committed
Jun 19, 2023
1 parent
4f57436
commit 0502414
Showing
3 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
const fs = require("fs"); | ||
const { env } = require("process"); | ||
const { PHASE_PRODUCTION_SERVER } = require("next/constants"); | ||
const CONFIG_ENV_VAR_NAME = "RPC_CONFIG"; | ||
const CONFIG_JSON = env[CONFIG_ENV_VAR_NAME]; | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
output: "standalone" | ||
}; | ||
|
||
module.exports = nextConfig; | ||
module.exports = (phase) => { | ||
const isProduction = phase === PHASE_PRODUCTION_SERVER; | ||
const saveConfigFile = isProduction && Boolean(CONFIG_JSON); | ||
|
||
if (saveConfigFile) { | ||
saveConfig(config); | ||
} | ||
|
||
return nextConfig; | ||
}; | ||
|
||
function saveConfig() { | ||
console.log( | ||
`Saving config file from '${CONFIG_ENV_VAR_NAME}' env variable value` | ||
); | ||
|
||
fs.writeFileSync("./data/config.json", CONFIG_JSON); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters