JKC*_*JKC 28 routes ports node.js express
我有一个快速服务器,并在构建它时在自己的路由上创建了几个"帮助"功能.我希望在不同的端口上访问这些路由.反正有没有在快递中这样做?
在下面的代码中,"/ factory"路由(和其他功能)将位于一个端口上,"/ killallthings","/ listallthings"和"/ killserver"的帮助程序路由将位于单独的端口上.
这是代码的简化版本:
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);
});
Run Code Online (Sandbox Code Playgroud)
快递可以吗?
JKC*_*JKC 34
基于上面的Explosion Pills建议,我大致以这种方式修改了代码:
var express = require('express');
var things = [];
var app = express();
var admin_app = express();
var port = 8080;
var admin_port = 8081;
app.post('/factory/', function(req, res) {
//Create a thing and add it to the thing array
});
//Assume more functions to do to things here....
admin_app.post('/killallthings/', function(req, res) {
//Destroy all the things in the array
});
admin_app.post('/listallthings/', function(req, res) {
// Return a list of all the things
});
admin_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);
});
var admin_server = require('https').createServer(options, admin_app);
admin_server.listen(admin_port, function() {
logger.writeLog('Listening on admin port ' + admin_port);
});
Run Code Online (Sandbox Code Playgroud)
我希望我知道如何将爆炸药作为答案的功劳!:)
| 归档时间: |
|
| 查看次数: |
18685 次 |
| 最近记录: |