ExpressJS路由问题

ExpressJS路由问题,express,routing,Express,Routing,我正在尝试将身份验证工作流移动到一个单独的路由器文件中 我有以下app.js: ... var index = require('./routes/index'); var auth = require('./routes/auth'); var app = express(); ... app.use('/', index); app.use('/auth', auth); ... // catch 404 and forward to error handler app.use(funct

我正在尝试将身份验证工作流移动到一个单独的路由器文件中

我有以下app.js:

...
var index = require('./routes/index');
var auth = require('./routes/auth');

var app = express();
...
app.use('/', index);
app.use('/auth', auth);
...
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});
以及以下路径/auth.js:

router.get('signin', function(req, res){
  // this gets called at localhost:3000/signin
})

router.get('google/callback:code', function(req, res, next){
  // this produces a not found error at localhost:3000/auth/google/callback
});
404错误发生在我调用
/auth/google/callback?code=…
时。知道我做错了什么吗?提前谢谢

?code=
是路线的一部分,而不是路线的一部分。因此,您可以从路由中删除
:code

router.get('/google/callback', function(req, res, next){

});
您可以访问函数中的代码,如下所示:

router.get('/google/callback', function(req, res, next){
  console.log(req.query.code);
});