Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Increment Port #263

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function reload (app, opts, server) {

return new Promise(function (resolve, reject) {
// Parameters variables
const port = opts.port || 9856
var port = opts.port || 9856
const httpsOption = opts.https || null
const httpServerOrPort = server || port
const forceWss = opts.forceWss || false
Expand Down Expand Up @@ -57,7 +57,7 @@ module.exports = function reload (app, opts, server) {
}

// Application setup
setupClientSideCode()
// setupClientSideCode(port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being done below in your changes so please remove the old call here


setupExpressAppRouting().then(function () {
if (!webSocketServerWaitStart) {
Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = function reload (app, opts, server) {

const webSocketString = forceWss ? 'wss://$3' : 'ws$2://$3'

reloadCode = reloadCode.replace('socketUrl.replace()', 'socketUrl.replace(/(^http(s?):\\/\\/)(.*:)(.*)/,' + (socketPortSpecified ? '\'' + webSocketString + socketPortSpecified : '\'' + webSocketString + '$4') + '\')')
reloadCode = reloadCode.replace('socketUrl.replace()', 'socketUrl.replace(/(^http(s?):\\/\\/)(.*:)(.*)/,' + (socketPortSpecified ? '\'' + webSocketString + (port || socketPortSpecified) : '\'' + webSocketString + '$4') + '\')')
}

// Websocket server setup
Expand Down Expand Up @@ -165,8 +165,19 @@ module.exports = function reload (app, opts, server) {
httpOrHttpsServer = http.createServer()
}

httpOrHttpsServer.listen(port, function () {
resolve(getReloadReturn())
function runServer(port) {
httpOrHttpsServer.listen(port, function () {
resolve(getReloadReturn(),)
setupClientSideCode(port)
})
}
runServer(port)

httpOrHttpsServer.once('error', function (err) {
if (err.code === 'EADDRINUSE') {
port = port + 1
runServer(port)
}
})

httpOrHttpsServer.on('upgrade', (request, socket, head) => {
Expand Down