- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的路线和路径设置如下:
var path1 = express.Router()
, path2 = express.Router()
// .. more modules, e.g. express-jwt ..
module.exports = function(app, passport) {
var path1Func = function(req, res) {
return MODEL.findById(req.params.id, function(err, model) {
if(!model) {
res.statusCode = 404;
return res.send({ status: '404 Not found' });
}
if(!err) {
return res.send({ status: 'OK', model:model });
} else {
res.statusCode = 500;
return res.send({ status: '500 Server error' });
}
});
};
// .. other functions which essentially look like above path1Func ..
path1.get('/subPath', path1Func );
path2.get('/otherSubPath', path2Func );
path2.post('/entirelyOtherSubPath', otherPath2Func );
app.use('/path1', path1);
app.use('/path2', path2);
app.use('/grid', expressJwt({secret: secret})); // Protect Paths
}
现在,根据我的 HTTP 请求、POST、GET 等的顺序,它们会被执行或返回 404 not find,这意味着 Express 不会解析某些请求,具体取决于 path1.get
、path2.get
、path2.post
的顺序。
上面的图片描绘了我看到的 404,具体取决于我的 paths.js 文件中路由声明的顺序。当我重新调整订单时,404 消失了,我得到了我想要的输出
这就是为什么我想使用 next() 来帮助我解决这个问题 - 请记住,我使用大量 app.use
使事情变得复杂。到目前为止,我自己还没能做到这一点。我仍然不清楚 next() 到底是什么以及如何在上面的示例中使用它来使我的路由器在每个路由中工作。为了节省空间,我没有把其他路由放在这里,但我的 API 已经相当大了,而且还会变得更大。
无论我的 POST
和 GET
请求的顺序如何,这里有什么方法可以让我的应用提供内容?
最佳答案
您所显示的特定请求收到 404 的原因是因为您没有匹配的路由模式。
您正在请求 /grid/dates/:val
但您只有 /grid
路线。即使您将 /grid
更改为 /grid/dates/:val
,您仍然不会响应请求,因为所有 expressJwt()
所做的是验证请求,然后将执行传递给下一个处理程序。因此,考虑到这一点,您可以尝试以下操作:
app.use('/grid/dates/:val',
expressJwt({secret: secret}),
function(req, res) {
res.send(200, 'hello world!');
});
关于node.js - Express.js/Node.js : Order of Routes important and where to put next()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219291/
我刚刚通过更改 import * as CodeMirror 修复了一个错误简单明了import CodeMirror . 我复制了this code . (从 TypeScript 移植) impo
我调试(在 PyCharm 中)一个脚本。我在断点处停止,然后转到调试控制台窗口,然后从那里调用导入行,如下所示: import my_util1 from my_utils 然后我调用 my_uti
谁能给我解释一下 import 语句是如何工作的? 例如,我在 myapp/app/models 包中有一个类型 User: package models type User struct {
我想导入 Control.App进入一个引用 PrimIO.PrimIO 的模块通过不合格的名称 PrimIO在很多地方。当然,问题在于 Control.App还导出一个名为 PrimIO 的定义.我
我应该使用 from foo import bar 或者 import foo.bar as bar 当导入模块 还有无需/希望更改名称 (bar)? 有什么不同吗?有关系吗? 最佳答案 假设 bar
我正在 Windows 上使用 Theano 进行深度学习实验的第一步,我很惊讶仅仅加载库需要多少时间。 这是小测试程序: from time import time t0 = time() impo
在 TypeScript 中,如何在不创建任何别名的情况下从文件“导入 *”? 例如我有一个包含顶级导出函数的文件“utils”,我想导入所有这些函数而不为每个函数重新创建别名。 像这样: impor
我应该使用 from foo import bar 或 import foo.bar as bar 当导入模块并且不需要/希望更改名称(bar)? 有什么不同吗?有关系吗? 最佳答案 假设bar是fo
这个问题在这里已经有了答案: Use 'import module' or 'from module import'? (23 个回答) 关闭8年前。 我想知道代码片段之间是否有任何区别 from u
我试过了 from urllib import request mine = request.Request() 和 import urllib.request mine = urllib.reque
所以,我有一个关于 Python 导入的小谜团。我确信出于某种原因事情应该是这样的,因为 Guido 很少出错。但是,为什么会这样呢? $ cat myModule.py #!/usr/bin/pyt
我们正在将 Rails 3.2 应用程序升级到 Rails 4.0。 我们有一个 assets/stylesheets/application/index.css.sass加载一些其他 sass 文件
我正在开发一个相当小的 Typescript 代码库,该代码库已经足够大,可以拆分到多个文件中。这是一个二十一点游戏。我目前有一堆代码,看起来像: var player = new Player();
是否可以以当模块为 use 时的方式编写模块? d 没有显式导入所有子例程都被导入,当它是 use d 显式导入只有这些显式导入的子程序可用? #!/usr/bin/env perl6 use v6;
这个问题在这里已经有了答案: how to watch changes in whole directory/folder containing many sass files (9 个回答) 5年前
我真的很难让它在 xcode 4 中工作。 我有一个项目将在许多应用程序(网络)中重用,因此我创建一个工作区并添加我的两个项目。到目前为止,一切都很好....这就是失败的地方.. #import "J
经典提取器和新提取器之间的主要区别是什么,哪个最好用? 最佳答案 经典提取器使用原始工作流程,与爬虫和连接器相同。 新的提取器更加精简,通常看起来和感觉都更好,并且经典提取器中的许多小错误已在新提取器
在处理 google webfont import mixin 时,我注意到无法动态构建 @import URL。 .gFontImport (@name, @weights, @subsets) {
我正在关注Django 1.8 tutorial 。在我的项目中mysite ,有一个源文件夹polls 。文件夹中有views.py模块其中 index函数已定义。还有一个urls.py文件: fr
我想使用名为 warp 的第三方库编译一个简单的 Rust 程序: [package] name = "hello-world-warp" version = "0.1.0" [dependencie
我是一名优秀的程序员,十分优秀!