Skip to content

Commit

Permalink
chore: adds write config file on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Green committed Jun 19, 2023
1 parent 4f57436 commit 0502414
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ ENV PORT 3000

VOLUME /app/data

# Allow passing through the RPC_CONFIG JSON configuration environment variable.
ARG RPC_CONFIG
ENV RPC_CONFIG="$RPC_CONFIG"

CMD ["node", "server.js"]
25 changes: 24 additions & 1 deletion next.config.js
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);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raspberry-pi-client",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 0502414

Please sign in to comment.