var express = require('express');
var app = express();
var PORT = 3000;
// This middleware will not allow the
// request to go beyond it
app.use(function (req, res, next) {
console.log("Middleware called")
next();
});
// Requests will never reach this route
为了寻找如何为微服务应用程序实现节点API网关的良好示例,我理解拥有网关的目的,只是不知道如何在不添加另一个级别的RESTful路由调用的情况下实现该网关。对我来说,网关应该是直接通向微服务的路线。
API网关端口3000
router.use('/microservicename/*', function (req, res, next) {
**code that will direct to microservice**
});
Microservice1 server.js端口3001
var express = require('express
注:我是新来的。
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('id: ' + req.params.id + ' and name: ' + req.params.name);
});
var things = require('./things/things.js');
//both index.js and things.js should be i
我想知道为什么我的路由器"/posts“没有运行,或者当我包含一个app.use()中间件时,它只是加载它的页面。
const express = require('express');
//Initialize Express
const app = express();
//Middleware
//When I comment this app.use line of code I can access the /posts router but when I left it uncommented
//My localhost sometimes error