From c1aa23aca9ac88125b34e24f155c577ef5fad39c Mon Sep 17 00:00:00 2001 From: Vijay A Date: Thu, 5 Aug 2021 15:03:07 +0530 Subject: fix: change all occurrences of hard-coded ip address '127.0.0.1' to 'localhost' Also refactored to make this a constant defined in a single file where it is imported for all other uses. fixes #1253 --- src/api/apiBase.js | 3 ++- src/config.js | 1 + src/electron/ipc-api/localServer.js | 3 ++- src/internal-server/app/Controllers/Http/ServiceController.js | 10 +++++++--- src/internal-server/config/session.js | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/api/apiBase.js b/src/api/apiBase.js index 3278dc454..db974c96f 100644 --- a/src/api/apiBase.js +++ b/src/api/apiBase.js @@ -7,6 +7,7 @@ import { import { DEV_API_FRANZ_WEBSITE, LIVE_FRANZ_API, + LOCAL_HOSTNAME, LOCAL_SERVER, SERVER_NOT_LOADED, } from '../config'; @@ -23,7 +24,7 @@ const apiBase = (withVersion = true) => { } if (window.ferdi.stores.settings.all.app.server === LOCAL_SERVER) { // Use URL for local server - url = `http://127.0.0.1:${window.ferdi.stores.requests.localServerPort}`; + url = `http://${LOCAL_HOSTNAME}:${window.ferdi.stores.requests.localServerPort}`; } else { // Load URL from store url = window.ferdi.stores.settings.all.app.server; diff --git a/src/config.js b/src/config.js index ef3e4f962..3598fa5d5 100644 --- a/src/config.js +++ b/src/config.js @@ -4,6 +4,7 @@ import ms from 'ms'; export const CHECK_INTERVAL = ms('1h'); // How often should we perform checks +export const LOCAL_HOSTNAME = 'localhost'; export const LOCAL_API = 'http://localhost:3000'; export const DEV_FRANZ_API = 'https://dev.franzinfra.com'; diff --git a/src/electron/ipc-api/localServer.js b/src/electron/ipc-api/localServer.js index 9b800fdf6..493253e17 100644 --- a/src/electron/ipc-api/localServer.js +++ b/src/electron/ipc-api/localServer.js @@ -1,5 +1,6 @@ import { ipcMain, app } from 'electron'; import net from 'net'; +import { LOCAL_HOSTNAME } from '../../config'; import startServer from '../../internal-server/start'; const DEFAULT_PORT = 45569; @@ -11,7 +12,7 @@ const portInUse = function (port) { socket.pipe(socket); }); - server.listen(port, '127.0.0.1'); + server.listen(port, LOCAL_HOSTNAME); server.on('error', () => { resolve(true); }); diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js index c30e9e040..e4a7f0295 100644 --- a/src/internal-server/app/Controllers/Http/ServiceController.js +++ b/src/internal-server/app/Controllers/Http/ServiceController.js @@ -5,6 +5,10 @@ const Env = use('Env'); const uuid = require('uuid/v4'); const path = require('path'); const fs = require('fs-extra'); +const { LOCAL_HOSTNAME } = require('../../../../config'); + +const hostname = LOCAL_HOSTNAME; +const port = Env.get('PORT'); class ServiceController { // Create a new service for user @@ -84,7 +88,7 @@ class ServiceController { workspaces: [], ...JSON.parse(service.settings), iconUrl: settings.iconId - ? `http://127.0.0.1:${Env.get('PORT')}/v1/icon/${settings.iconId}` + ? `http://${hostname}:${port}/v1/icon/${settings.iconId}` : null, id: service.serviceId, name: service.name, @@ -152,7 +156,7 @@ class ServiceController { id, name: service.name, ...newSettings, - iconUrl: `http://127.0.0.1:${Env.get('PORT')}/v1/icon/${ + iconUrl: `http://${hostname}:${port}/v1/icon/${ newSettings.iconId }`, userId: 1, @@ -258,7 +262,7 @@ class ServiceController { workspaces: [], ...JSON.parse(service.settings), iconUrl: settings.iconId - ? `http://127.0.0.1:${Env.get('PORT')}/v1/icon/${settings.iconId}` + ? `http://${hostname}:${port}/v1/icon/${settings.iconId}` : null, id: service.serviceId, name: service.name, diff --git a/src/internal-server/config/session.js b/src/internal-server/config/session.js index 62c4f9cc8..3ce3cc4da 100644 --- a/src/internal-server/config/session.js +++ b/src/internal-server/config/session.js @@ -88,7 +88,7 @@ module.exports = { | */ redis: { - host: '127.0.0.1', + host: 'localhost', port: 6379, password: null, db: 0, -- cgit v1.2.3-54-g00ecf