【问题标题】:Router not found in NodeJS在 NodeJS 中找不到路由器
【发布时间】:2015-12-10 21:23:33
【问题描述】:

我正在研究 NodeJs 和 localhost,一切正常,但是,当我在 azure 中部署时,我得到了这个错误:

错误:未找到 在 app.use.res.render.message (D:\home\site\wwwroot\app.js:43:13) 在 Layer.handle [as handle_request] (D:\home\site\wwwroot\node_modules\express\lib\router\layer.js:95:5) 在 trim_prefix (D:\home\site\wwwroot\node_modules\express\lib\router\index.js:312:13) 在 D:\home\site\wwwroot\node_modules\express\lib\router\index.js:280:7 在 Function.process_params (D:\home\site\wwwroot\node_modules\express\lib\router\index.js:330:12) 在下一个(D:\home\site\wwwroot\node_modules\express\lib\router\index.js:271:10) 在 SessionStrategy.strategy.pass (D:\home\site\wwwroot\node_modules\passport\lib\middleware\authenticate.js:318:9) 在 SessionStrategy.authenticate (D:\home\site\wwwroot\node_modules\passport\lib\strategies\session.js:71:10) 尝试(D:\home\site\wwwroot\node_modules\passport\lib\middleware\authenticate.js:341:16) 在验证(D:\home\site\wwwroot\node_modules\passport\lib\middleware\authenticate.js:342:7)

下面是我的代码: https://gist.github.com/StephanyBatista/3a2bfdd9aa3f9b7d170f

我的疑问是为什么这段代码在 localhost 中可以,而在 azure 中不行?

【问题讨论】:

  • 我已经看到,当我删除“express-load”并放入 app.js 时,它起作用了。

标签: javascript node.js azure


【解决方案1】:

嗯,嗯,你正在使用:

app.use(function(err, req, res, next)

definition 是:

app.use(function(req, res, next)

所以 next 为 null,因为 err = req、req = res、res = next 和 next 为 null(您已经转移了参数)。

就像您在上一个函数中使用它一样。有关 middleware 的更多信息,解释了它为什么会这样工作。

【讨论】:

  • 我按照你的建议,删除了中间件,仍然出现“未找到”错误。
  • 如果您删除了某些内容,则错误出在其他代码行上。据我所知,您已经使用了两次 app.use(function(err, req, res, next),因此您需要删除它们,如果仍然有任何错误,请更新您发布的代码。
猜你喜欢
  • 2015-05-12
  • 1970-01-01
  • 2017-09-25
  • 2016-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多