Add HOST environment

This is necessary in order to override which IP the Dashy process will bind to.
This commit is contained in:
PlusaN 2022-05-22 00:58:59 +03:00 committed by GitHub
parent 78bed0fb92
commit f700f31904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -38,6 +38,9 @@ const isDocker = !!process.env.IS_DOCKER;
/* Checks env var for port. If undefined, will use Port 80 for Docker, or 4000 for metal */ /* Checks env var for port. If undefined, will use Port 80 for Docker, or 4000 for metal */
const port = process.env.PORT || (isDocker ? 80 : 4000); const port = process.env.PORT || (isDocker ? 80 : 4000);
/* Checks env var for host. If undefined, will use 0.0.0.0 */
const host = process.env.HOST || '0.0.0.0';
/* Attempts to get the users local IP, used as part of welcome message */ /* Attempts to get the users local IP, used as part of welcome message */
const getLocalIp = () => { const getLocalIp = () => {
const dnsLookup = util.promisify(dns.lookup); const dnsLookup = util.promisify(dns.lookup);
@ -48,7 +51,7 @@ const getLocalIp = () => {
const printWelcomeMessage = () => { const printWelcomeMessage = () => {
try { try {
getLocalIp().then(({ address }) => { getLocalIp().then(({ address }) => {
const ip = address || 'localhost'; const ip = process.env.HOST || address || 'localhost';
console.log(printMessage(ip, port, isDocker)); // eslint-disable-line no-console console.log(printMessage(ip, port, isDocker)); // eslint-disable-line no-console
}); });
} catch (e) { } catch (e) {
@ -122,7 +125,7 @@ const app = express()
/* Create HTTP server from app on port, and print welcome message */ /* Create HTTP server from app on port, and print welcome message */
http.createServer(app) http.createServer(app)
.listen(port, () => { .listen(port, host, () => {
printWelcomeMessage(); printWelcomeMessage();
}) })
.on('error', (err) => { .on('error', (err) => {