From 6bbfa565ed33a6c2943416e76525b29bc8db44df Mon Sep 17 00:00:00 2001 From: Mischa Radenovic Date: Sat, 18 Jan 2020 23:41:51 -0500 Subject: [PATCH] Fix ERR_CONNECTION_REFUSED for Chrome OS When installed on Linux on Chrome OS, the server is not accessible in Google Chrome out of the box. To map ports automaticaly, host parameter needs to be passed to a express app.listen() call. Fixes #4 --- config.js | 1 + server.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index cc42656..2af824a 100644 --- a/config.js +++ b/config.js @@ -1,2 +1,3 @@ exports.port = process.env.PORT || 5001 +exports.host = process.env.HOST || 'localhost' exports.origin = process.env.ORIGIN || `http://localhost:${exports.port}` diff --git a/server.js b/server.js index 24f3b5e..d5b3aa4 100644 --- a/server.js +++ b/server.js @@ -62,6 +62,6 @@ app.post('/contacts', bodyParser.json(), (req, res) => { } }) -app.listen(config.port, () => { +app.listen(config.port, config.host, () => { console.log('Server listening on port %s, Ctrl+C to stop', config.port) })