diff --git a/bin/codecept-ui.js b/bin/codecept-ui.js index 9b7ac65..1a8aaf9 100755 --- a/bin/codecept-ui.js +++ b/bin/codecept-ui.js @@ -1,5 +1,6 @@ #!/usr/bin/env node const debug = require('debug')('codepress:codepress'); +const { getPort } = require('../lib/config/env'); // initialize CodeceptJS require('../lib/commands/init')(); @@ -13,7 +14,7 @@ const snapshotStore = require('../lib/model/snapshot-store'); const scenarioStatusRepository = require('../lib/model/scenario-status-repository'); // Base port -const PORT = 3000; +const PORT = getPort(); // Serve frontend from dist const AppDir = path.join(__dirname, '..', 'dist'); diff --git a/lib/api/list-steps.js b/lib/api/list-steps.js index 0134a77..5ea33d6 100644 --- a/lib/api/list-steps.js +++ b/lib/api/list-steps.js @@ -1,7 +1,8 @@ +const { getUrl } = require('../config/url'); const { event } = require('codeceptjs'); const codeceptjsFactory = require('../model/codeceptjs-factory'); -const WS_URL = 'http://localhost:3000'; +const WS_URL = getUrl(); const TestProjectDir = process.cwd(); diff --git a/lib/codeceptjs/brk.js b/lib/codeceptjs/brk.js index 1969dab..04ef6ba 100644 --- a/lib/codeceptjs/brk.js +++ b/lib/codeceptjs/brk.js @@ -1,3 +1,4 @@ +const { getUrl } = require('../config/url'); const container = require('codeceptjs').container; const store = require('codeceptjs').store; const recorder = require('codeceptjs').recorder; @@ -32,7 +33,7 @@ const pause = function () { }; function pauseSession() { - socket = require('socket.io-client')('http://localhost:3000'); + socket = require('socket.io-client')(getUrl()); rl = readline.createInterface(process.stdin, process.stdout); recorder.session.start('pause'); diff --git a/lib/config/env.js b/lib/config/env.js new file mode 100644 index 0000000..cf71856 --- /dev/null +++ b/lib/config/env.js @@ -0,0 +1,5 @@ +module.exports = { + getPort() { + return Number(process.env.port) || 3000; + } +}; \ No newline at end of file diff --git a/lib/config/url.js b/lib/config/url.js new file mode 100644 index 0000000..15df5aa --- /dev/null +++ b/lib/config/url.js @@ -0,0 +1,8 @@ +const { getPort } = require('./env'); + +module.exports = { + getUrl() { + const PORT = getPort(); + return `http://localhost:${PORT}`; + } +}; \ No newline at end of file diff --git a/lib/model/ws-events.js b/lib/model/ws-events.js index d0ba5d4..7c7a2d1 100644 --- a/lib/model/ws-events.js +++ b/lib/model/ws-events.js @@ -1,4 +1,5 @@ -const WS_URL = 'http://localhost:3000'; +const { getUrl } = require('../config/url'); +const WS_URL = getUrl(); const socket = require('socket.io-client')(WS_URL); diff --git a/package-lock.json b/package-lock.json index a5c627c..f561e05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@codeceptjs/ui", - "version": "0.2.1", + "version": "0.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/main.js b/src/main.js index 798b054..185ad53 100644 --- a/src/main.js +++ b/src/main.js @@ -17,9 +17,10 @@ Vue.use(Buefy); Vue.use(VueHighlightJS); const store = require('./store').default; +const PORT = process.env.port || 3000; Vue.use(new VueSocketIO({ debug: true, - connection: 'http://localhost:3000', + connection: `http://localhost:${PORT}`, vuex: { store, actionPrefix: 'SOCKET_', diff --git a/vue.config.js b/vue.config.js index 19a977f..32ff11d 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,8 +1,10 @@ +const { getUrl } = require('./lib/config/url'); + module.exports = { devServer: { proxy: { '^/api': { - target: 'http://localhost:3001/', + target: getUrl(), } } }