I have an express server, and while building it created several "helper" functions on their own routes. I'd like those routes to be accessed on a different port. Is there anyway to do this in express?
In the code below, the "/factory" route (and other functionality) would be on one port, and the helper routes of "/killallthings", "/listallthings", and "/killserver" would be on a separate port.
Here is a simplified version of the code:
var express = require('express');
var things = [];
var app = express();
var port = 8080;
app.post('/factory/', function(req, res) {
//Create a thing and add it to the thing array
});
//Assume more functions to do to things here....
app.post('/killallthings/', function(req, res) {
//Destroy all the things in the array
});
app.post('/listallthings/', function(req, res) {
// Return a list of all the things
});
app.post('/killserver/', function(req,res){
//Kills the server after killing the things and doing clean up
});
//Assume https options properly setup.
var server = require('https').createServer(options, app);
server.listen(port, function() {
logger.writeLog('Listening on port ' + port);
});
Is this possible with express?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…