Skip to content

Commit

Permalink
Use $PORT inside example server
Browse files Browse the repository at this point in the history
  • Loading branch information
willmorgan committed Jan 22, 2021
1 parent 2f588c0 commit 0e4cd4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions demo/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Load and validate configuration
* @todo Use Joi or some better configuration checker
* @param env an object that contains the configuration, like process.env
* @return {{API_KEY: *, API_SECRET: *, BASE_URL: *, EXAMPLE_SERVER_PORT: *}}
* @return {{API_KEY: *, API_SECRET: *, BASE_URL: *, EXAMPLE_SERVER_PORT: *, PORT: *}}
*/
export function configure(env) {
const { BASE_URL, API_KEY, API_SECRET } = env
let { EXAMPLE_SERVER_PORT } = env
let { PORT, EXAMPLE_SERVER_PORT } = env
const errors = []
if (!BASE_URL) {
errors.push("BASE_URL is undefined. Example: https://eu.rp.secure.iproov.me.")
Expand All @@ -23,6 +23,10 @@ export function configure(env) {
} else if (API_SECRET.length < 40) {
errors.push("API_SECRET seems incorrect, it should be a 40 character alphanumeric string.")
}
if (!PORT) {
// This is the internal container port that the EXAMPLE_SERVER_PORT should map to. Best left at 80.
PORT = 80
}
if (!EXAMPLE_SERVER_PORT) {
console.warn("EXAMPLE_SERVER_PORT not specified, using port 80.")
EXAMPLE_SERVER_PORT = 80
Expand All @@ -34,11 +38,11 @@ export function configure(env) {
process.exit(1)
return
}
const config = {
return {
BASE_URL,
API_KEY,
API_SECRET,
PORT,
EXAMPLE_SERVER_PORT,
}
return config
}
4 changes: 2 additions & 2 deletions demo/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { configure } from "./config.js"
const __dirname = fileURLToPath(dirname(import.meta.url))

async function init() {
const { BASE_URL, API_KEY, API_SECRET, EXAMPLE_SERVER_PORT } = configure(process.env)
const { BASE_URL, API_KEY, API_SECRET, PORT, EXAMPLE_SERVER_PORT } = configure(process.env)

const ALL_INTERFACES = "0.0.0.0" // listen on all interfaces so Docker can bind
const server = Hapi.server({
port: 80,
port: PORT,
host: ALL_INTERFACES,
})

Expand Down

0 comments on commit 0e4cd4b

Please sign in to comment.