Javascript Nodejs-设置不同的api版本

Javascript Nodejs-设置不同的api版本,javascript,node.js,Javascript,Node.js,我有以下api版本1的设置,它将通过中间件验证令牌 var app = express(); // Auth Middleware - This will check if the token is valid // Only the requests that start with /api/version1/* will be checked for the token. // Any URL's that do not follow the below pattern should be

我有以下api版本1的设置,它将通过中间件验证令牌

var app = express();
// Auth Middleware - This will check if the token is valid
// Only the requests that start with /api/version1/* will be checked for the token.
// Any URL's that do not follow the below pattern should be avoided unless you 
// are sure that authentication is not needed
app.all('/api/version1/*', [require('./middleWare/validateMyRequest')]);
app.use('/', require('./myModal'));
app.all('/*', function(req, res) {
    res.sendFile('/public/index.html', { root: __dirname });
});
在这里,我想在服务器配置中设置另一个api版本2,我不需要使用中间件验证令牌

app.use('/api/version2/*', require('./myModal'));

当我尝试使用api版本为2的baseurl时。它总是验证令牌并重定向到登录页面。请告知我在这里缺少什么来设置api版本2?

将两个单独的api分别放在各自的路由器上。然后,您可以在每个路由器上使用不同的中间件,一个执行一种验证/身份验证,另一个执行不同的操作

app.use('/api/version1', router1);
app.use('/api/version2', router2);


router1.use(require('./middleWare/validateMyRequest'));
router1.get('/whatever', function(req, res) {
    // handle /api/version1/whatever here
});


router2.get('/something', function(req, res) {
    // handle /api/version2/something here
});