小编JKC*_*JKC的帖子

NodeJS 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 …
Run Code Online (Sandbox Code Playgroud)

routes ports node.js express

28
推荐指数
1
解决办法
2万
查看次数

标签 统计

express ×1

node.js ×1

ports ×1

routes ×1