-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomasz Rakowski
committed
Jun 12, 2019
1 parent
a2ff6a9
commit 72a8c63
Showing
17 changed files
with
444 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = (serverList, portMap = {}) => { | ||
for (const port in serverList) { | ||
if (serverList[port] && !portMap[port]) { | ||
console.info('Shutting down port:' + port); | ||
serverList[port].close(() => { | ||
console.debug('Instance shut down'); | ||
}); | ||
delete serverList[port]; | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const vhost = require('./vhost'); | ||
|
||
module.exports = (config, oStack, serverList, handler) => { | ||
|
||
const port_map = {}; // Holds a list of all ports and protocols; | ||
|
||
const output = {}; | ||
|
||
output.load = () => { | ||
const arr_vhost_objects = []; // Holds a list of vhost Objects | ||
|
||
let arr_vhost_config = []; // Holds a list of vhost configurations | ||
|
||
if(config.controller.vhost) { | ||
|
||
if(config.controller.vhost.list) { | ||
arr_vhost_config = arr_vhost_config.concat(config.controller.vhost.list); | ||
} | ||
|
||
if(config.controller.vhost.path) { | ||
arr_vhost_config = arr_vhost_config.concat(require('./scan-vhost-dir')(config.controller.vhost.path)); | ||
} | ||
|
||
if(arr_vhost_config) { | ||
arr_vhost_config.forEach(hostConf => { | ||
const ovh = new vhost(hostConf, config.node.global_path); | ||
if (port_map[ovh.config.vhost.port] && port_map[ovh.config.vhost.port] !== ovh.config.vhost.protocol) { | ||
throw new Error('Invalid configuration. Requested port already used by a different protocol: ' + ovh.config.vhost.port + ' mapped to ' + port_map[ovh.config.vhost.port]); | ||
} | ||
port_map[ovh.config.vhost.port] = ovh.config.vhost.protocol; | ||
arr_vhost_objects.push(ovh); | ||
}); | ||
} | ||
} | ||
|
||
oStack.list = arr_vhost_objects; | ||
console.info('All vhosts reloaded'); | ||
|
||
// Shutting down server ports that are not needed anymore; | ||
console.info('Shutting down any unneeded ports'); | ||
output.close(); | ||
// Adding any missing ports | ||
console.info('Starting any additional ports'); | ||
for (const port in port_map) { | ||
if (!serverList[port]) { | ||
const protocol = port_map[port]; | ||
const s = require(protocol).createServer(handler).listen(port, (err) => { | ||
console.info('Listening on port %d', s.address().port); | ||
}); | ||
serverList[port] = s; | ||
console.info('Started on port:' + port); | ||
} | ||
} | ||
}; | ||
|
||
output.close = () => { | ||
require('./close')(serverList, {}); | ||
}; | ||
|
||
return output; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
|
||
module.exports = (pathname) => { | ||
let output = []; | ||
fs.readdirSync(path.join(pathname)).forEach(file => { | ||
if (file.match(/\.vhost\.js$/)) { | ||
try { | ||
console.debug('Loading vhost from file: ' + path.join(pathname, file)); | ||
const m = path.join(pathname, file); | ||
delete require.cache[m]; | ||
output.push(require(m)); | ||
} catch(e) { | ||
console.error(e); | ||
} | ||
} | ||
}); | ||
return output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.