问题标签 [koa-router]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
node.js - 如何将我的 koa 路由拆分为单独的文件?
我试图弄清楚如何将我的路线拆分成单独的文件。
到目前为止我有这个,但它不起作用。我只是Not found
在尝试访问时得到http://localhost:3001/api/things
node.js - 使用 koa (nodejs) 发布
我一直在寻找仅解析发送的 JSON 的示例,这很烦人。我试图找到一个 POST 来自表单的示例。
如您所见,我有字段email
和password
. 我正在使用koa-router
它拥有快速风格的路由,但这不起作用:
koa - 使用 koa-router 和 koa-mount 处理无效请求
我的应用程序使用 koa-router,它使用 koa-mount 安装路由器,如下所示:
期望的行为是以未定义的开头的路由api
应该给出 503或其他内容。相反,请求会落入 RedisBoot 处理程序。我尝试在开头和结尾添加其他规则,router
但由于某种原因,它们似乎没有被调用。
我注意到较新版本的 koa-router 支持嵌套路由并具有其他一些不错的功能,所以现在没有 koa-mount 可能更容易让它工作?
koa - koa-route 无法运行
为什么下面的代码输出为“一”,而不是“一”“二”?但使用 express-route 是可以的
node.js - 如何配置 koa-router 在任何一组路由之前运行通用代码?
我想/module
为该目录下的任何匹配路由添加一些功能。
所以对于给定的一组路线:
我希望路由器中的代码为/module
上述所有路由运行。/module
不渲染,它只是获取一些公共数据并配置视图上下文。然后其他路由之一运行并呈现页面。
koa-router可以做到这一点吗?还是有更好的包?
编辑:我想也许我必须做一个嵌套路由器并在嵌套之前添加中间件,如下所示:
似乎正在工作,但我不确定这是一个丑陋的黑客还是什么。如果有更好的方法,请指教。
javascript - 如何为基于 KOA 的服务器生成 API 文档
我有一个基于 KOA 的服务器。现在我想为服务器生成 API 文档。有没有自动生成 API Docs 的工具
javascript - JS Regex to match Chars with - or without -
I want to be able to match either of the following:
so match on chars with or without dashes, allow either.
the purpose of this is so I can allow uris coming into my router to match on.
for example I want to allow flexibility on a-z and allow any words to be separated since we might allow callers to send in seo-friendly values
etc.
I'm using koa-controller and trying to come up with a regex route to allow this. As far as I know I think koa-controller uses middleware path-to-regexp
What I'm asking is not unclear to whoever didn't understand. I'm simply trying to create a route with regex for my koa-controller routes that will allow callers to send in urls that allow names whereas the names could have dashes or not.
Here's what I tried with no luck. I'm either not getting the regex right or syntax right with how you add a regex to a koa-route or both wrong at the same time, I don't know which:
all these were attempts to get this working above, I tried all those different route definitions and none would match on for example an incoming request of:
/countries/united-states-of-america/states/illinois/cities/chicago
just as an example. I'm just trying to get a route defined for my koa routes that works.
the countryUrlFriendlyName for example are just named params that map to my controller action methods in koa-controller middleware. I want to allow people to send in values for those params with dashes or not.
I have a controller which these params are mapped to. So the to: part means I'm mapping to a function named after # that those :[param name] maps to.
And as you can see there's more to the story, the route is a bit longer but I was trying to concentrate on just trying to get the regex working for country as an example. My full route allows countries/[name]/states/name/cities/[name] and it's the [name] which I wanna allow them to send in with hyphens or not and yes the hyphens could be there, or random or not there.
I'm allowing our web team to request a match on some seo names they send into our API.
node.js - 为什么koa-router发送404?
我正在使用 koa-router、koa-views 和 sequelize。数据来自数据库,但状态 = 404。我做错了什么?
koa - koa 是否服务于取消的请求?
我在 koa 中有一个端点,它从数据库中加载大量数据,然后根据它计算一些结果。这可能需要几秒钟。
如果浏览器取消请求,请求会发生什么?就像浏览器选项卡被关闭等。
例如,cache.c
即使浏览器取消或 koa 足够聪明,可以简单地停止它为此请求启动的任何操作,也会被填充?
javascript - 如何在 Promise 或回调中运行 `yield next`?
我一直在为 koa 应用程序编写身份验证路由器。
我有一个从数据库获取数据然后将其与请求进行比较的模块。我只想yield next
在身份验证通过时运行。
问题是与数据库通信的模块返回一个承诺,如果我尝试yield next
在该承诺内运行,我会收到错误。要么SyntaxError: Unexpected strict mode reserved word
或SyntaxError: Unexpected identifier
取决于是否使用严格模式。
这是一个简化的示例: