Skip to content

Commit dfb68f5

Browse files
author
Russell Green
committed
chore: updates
1 parent c5d74e6 commit dfb68f5

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ COPY --from=builder /app/public ./public
4646
# https://nextjs.org/docs/advanced-features/output-file-tracing
4747
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
4848
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
49+
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
4950

5051
USER nextjs
5152

@@ -59,4 +60,5 @@ VOLUME /app/data
5960
ARG RPC_CONFIG
6061
ENV RPC_CONFIG="$RPC_CONFIG"
6162

63+
ENTRYPOINT ["node", "scripts/initialize-environment.js"]
6264
CMD ["node", "server.js"]

lib/level/LevelSensor.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,19 @@ export abstract class LevelSensor {
5555

5656
async getLevel(): Promise<number> {
5757
const endpoint = `${this.sensorEndpoint}/${this.options.endpointPath}`;
58+
const { retryCount, retryWait } = this.options;
5859
try {
5960
const response: LevelSensorResponse = await this.piServer.requestJson({
6061
endpoint,
61-
retryCount: this.options.retryCount,
62-
retryWait: this.options.retryWait
62+
retryCount,
63+
retryWait
6364
});
6465

6566
return response.distance;
6667
} catch (error) {
67-
this.log.error(`Failed to get level at endpoint: '${endpoint}'`);
68+
this.log.error(
69+
`Failed to get level at endpoint: '${endpoint}' (retryCount: ${retryCount} retryWait: ${retryWait})`
70+
);
6871
throw error;
6972
}
7073
}

next.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require("fs");
22
const { env } = require("process");
3+
const { version } = require("./package.json");
34
const { PHASE_PRODUCTION_SERVER } = require("next/constants");
45
const CONFIG_ENV_VAR_NAME = "RPC_CONFIG";
56

@@ -20,7 +21,9 @@ module.exports = (phase) => {
2021
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists.`
2122
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`;
2223

23-
console.log(`Initializing app in '${mode}' mode. ${configInfo}`);
24+
console.log(
25+
`Initializing app version '${version}' in '${mode}' mode. ${configInfo}`
26+
);
2427
if (saveConfigFile) {
2528
saveConfig(config);
2629
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "raspberry-pi-client",
3-
"version": "1.0.0-rc.3",
3+
"version": "1.0.0-rc.4",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

scripts/initialize-environment.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const fs = require("fs");
2+
const { env } = require("process");
3+
const { version } = require("./package.json");
4+
const configEnvName = "RPC_CONFIG";
5+
const configJson = env[configEnvName];
6+
const nodeEnv = env["NODE_ENV"];
7+
const configFilePath = "./data/config.json";
8+
9+
function initializeConfig() {
10+
const hasConfig = Boolean(configJson);
11+
const message = hasConfig
12+
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists. File will be written to disk.`
13+
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`;
14+
15+
console.log(message);
16+
if (hasConfig) {
17+
saveConfig(config);
18+
}
19+
}
20+
21+
function saveConfig() {
22+
const configJson = env[CONFIG_ENV_VAR_NAME];
23+
fs.writeFileSync(configFilePath, configJson);
24+
console.log(`Config file written to '${configFilePath}'`);
25+
}
26+
27+
function initialize() {
28+
console.log(`Initializing app version '${version}' in '${nodeEnv}' mode.`);
29+
initializeConfig();
30+
}
31+
32+
initialize();

0 commit comments

Comments
 (0)