diff --git a/.env.sample b/.env.sample index 5da68b4f..79f3f2f8 100644 --- a/.env.sample +++ b/.env.sample @@ -8,12 +8,12 @@ LEON_LANG=en-US LEON_NODE_ENV=development # Server -LEON_SERVER_HOST=localhost +LEON_SERVER_HOST=http://localhost LEON_SERVER_PORT=1337 # Web app -LEON_WEBAPP_HOST=localhost -LEON_WEBAPP_PORT=4242 +LEON_WEBAPP_HOST=http://localhost +LEON_WEBAPP_PORT=1337 # Time zone (current one by default) LEON_TIME_ZONE= diff --git a/app/js/client.es6.js b/app/js/client.es6.js index cc6bbf06..719d6539 100644 --- a/app/js/client.es6.js +++ b/app/js/client.es6.js @@ -8,7 +8,7 @@ export default class Client { this.host = host this.port = port this._input = input - this.socket = io.connect(`http://${this.host}:${this.port}`) + this.socket = io.connect(`${this.host}:${this.port}`) this.history = localStorage.getItem('history') this.parsedHistory = [] this.info = res @@ -58,7 +58,7 @@ export default class Client { }) this.socket.on('download', (data) => { - window.location = `http://${config.server_host}:${config.server_port}/v1/downloads?package=${data.package}&module=${data.module}` + window.location = `${config.server_host}:${config.server_port}/v1/downloads?package=${data.package}&module=${data.module}` }) if (this.history !== null) { diff --git a/app/js/main.es6.js b/app/js/main.es6.js index 419db2bc..0d4dca67 100644 --- a/app/js/main.es6.js +++ b/app/js/main.es6.js @@ -21,7 +21,7 @@ document.addEventListener('DOMContentLoaded', () => { loader.start() - request.get(`http://${config.server_host}:${config.server_port}/v1/info`) + request.get(`${config.server_host}:${config.server_port}/v1/info`) .end((err, res) => { if (err || !res.ok) { console.error(err.response.error.message) diff --git a/hotword/index.js b/hotword/index.js index 925ecbc0..3268b577 100644 --- a/hotword/index.js +++ b/hotword/index.js @@ -10,9 +10,9 @@ const record = require('node-record-lpcm16') const { Detector, Models } = require('snowboy') const io = require('socket.io-client') -process.env.LEON_SERVER_HOST = process.env.LEON_SERVER_HOST || 'localhost' +process.env.LEON_SERVER_HOST = process.env.LEON_SERVER_HOST || 'http://localhost' process.env.LEON_SERVER_PORT = process.env.LEON_SERVER_PORT || 1337 -const url = `http://${process.env.LEON_SERVER_HOST}:${process.env.LEON_SERVER_PORT}` +const url = `${process.env.LEON_SERVER_HOST}:${process.env.LEON_SERVER_PORT}` const socket = io(url) socket.on('connect', () => { diff --git a/scripts/app/serve-app.js b/scripts/app/serve-app.js index fdb31881..8ae9bd39 100644 --- a/scripts/app/serve-app.js +++ b/scripts/app/serve-app.js @@ -32,7 +32,7 @@ export default () => new Promise((resolve) => { bs.init({ host: devip(), - port: process.env.LEON_WEBAPP_PORT, + port: 4242, open: true, server: { baseDir: 'app/', diff --git a/server/src/middleware/cors.js b/server/src/middleware/cors.js index e48c3f8c..d7745c7d 100644 --- a/server/src/middleware/cors.js +++ b/server/src/middleware/cors.js @@ -5,7 +5,11 @@ */ const corsMidd = (req, res, next) => { // Allow only a specific client to request to the API (depending of the env) - res.header('Access-Control-Allow-Origin', `http://${process.env.LEON_WEBAPP_HOST}:${process.env.LEON_WEBAPP_PORT}`) + if (process.env.NODE_ENV === 'production') { + res.header('Access-Control-Allow-Origin', `${process.env.LEON_WEBAPP_HOST}:${process.env.LEON_WEBAPP_PORT}`) + } else { + res.header('Access-Control-Allow-Origin', `${process.env.LEON_WEBAPP_HOST}:4242`) + } // Allow several headers for our requests res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')