- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用命令 fastify-cligenerate
设置了带有 fastify-cli 库的 fastify 框架。它具有开箱即用的 fastify-autoload 插件。
但是,当我添加自己的服务时,除了 model.js 和 schema.js 文件之外,它会抛出错误。
...
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'services'),
options: Object.assign({}, opts),
ignorePattern: /.*(model|schema)\.js/
})
...
错误消息:
assert.js:788
throw newErr;
^
AssertionError [ERR_ASSERTION]: ifError got unwanted exception: plugin must be a function
at wrap (D:\project\kuisioner\backend\node_modules\fastify-cli\start.js:124:5)
...
actual: Error: plugin must be a function
...
error Command failed with exit code 1.
...
但是我手动注册就可以顺利运行
...
fastify.register(require('./services/quiz/get'))
fastify.register(require('./services/quiz/post'))
...
我的文件结构:
- src
- plugins
- db.js
- services
| - quiz
| - get.js
| - model.js
| - post.js
| - schema.js
- app.js
我使用 fastify-cli fastify start -l info src/app.js
来运行我的代码
最佳答案
检查您的存储库,错误是 dir
值。必须指向文件所在目录,暂不支持递归加载
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'services/quiz'),
options: Object.assign({}, opts),
ignorePattern: /.*(model|schema)\.js/
})
通过此更改,npm start
将起作用。
另一种选择是在需要跳过的文件中使用module.exports.autoload = false
,但你的正则表达式没问题。
关于javascript - Fastify 插件 fastify-autoload 错误插件必须是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57932375/
在 fastify 中,有没有办法为路由/路径添加别名?基本上,以相同的方式处理两条路径。这对于迁移 API 很有用。 我知道我可以将处理程序函数抽象为一个命名函数,并将该函数传递给两个路由。我只是想
在 fastify 中,有没有办法为路由/路径添加别名?基本上,以相同的方式处理两条路径。这对于迁移 API 很有用。 我知道我可以将处理程序函数抽象为一个命名函数,并将该函数传递给两个路由。我只是想
如您所知,Fastify 中的默认错误界面如下所示 { "statusCode": 400, "error": "Bad Request", "message": "Missi
我已经使用命令 fastify-cligenerate 设置了带有 fastify-cli 库的 fastify 框架。它具有开箱即用的 fastify-autoload 插件。 但是,当我添加自己的
如何从请求中访问属于非文件 字段的文本? (我正在使用 Insomia ) 我们使用 Insomia 的请求 我们可以通过遍历部分来访问文件字段。使用 const parts = await req.
如何从请求中访问属于非文件 字段的文本? (我正在使用 Insomia ) 我们使用 Insomia 的请求 我们可以通过遍历部分来访问文件字段。使用 const parts = await req.
我能够创建 jwt token : fastify.post('/signup', (req, reply) => { const token = fastify.jwt.sign({ p
我能够创建 jwt token : fastify.post('/signup', (req, reply) => { const token = fastify.jwt.sign({ p
对于每条路线,我都必须键入相同的标题,如下所示。有没有办法全局设置这些 header ,以便默认情况下将它们用于每个路由,并且可以在每个路由的基础上进行覆盖? fastify.post("/api/u
对于每条路线,我都必须键入相同的标题,如下所示。有没有办法全局设置这些 header ,以便默认情况下将它们用于每个路由,并且可以在每个路由的基础上进行覆盖? fastify.post("/api/u
我对何时在 Fastify.js 中使用插件有点困惑。例如,如果我只有一个包含一些实用函数的 lib/utils.js 文件,我通常会在我的应用程序中需要的地方只require() 它们。改为制作我的
我长期以来一直是 ExpressJs 的粉丝,但在 Youtube 视频中我偶然发现了 Fastify 并想尝试一下 我正在努力制作 fastify-swagger插件工作,我认为它应该工作 - 动态
我正在寻找如何使用 fastify-nextjs 启动 fastify-cli 的建议 我曾尝试将代码简单地添加到建议的位置,但它不起作用。 'use strict' const path = req
我的代码中有这个路由器 fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply
我正在尝试在我的拦截器中设置响应 header ,并且我发现的任何方法都没有运气。我试过了: const request = context.switchToHttp().getRequest();
我是 node.js 的 fastify 框架的新手,我想知道 fastify-plugin 的确切用途是什么 因为我无法理解它背后的想法。我尝试了一些带有或不带有插件的代码,但我没有注意到其中的区别
试图让中间件在 Fastify 中工作 - 我似乎无法访问查询或参数。文档说: Fastify supports out of the box Express/Restify/Connect midd
上下文:我对请求和响应时间感兴趣。 知道请求何时由 Fastify 管理的第一种方法是添加一个钩子(Hook),如下所示: fastify.addHook('onRequest', (request,
上下文:我对请求和响应时间感兴趣。 知道请求何时由 Fastify 管理的第一种方法是添加一个钩子(Hook),如下所示: fastify.addHook('onRequest', (request,
正如你想象的那样,我对 Express 很熟悉,但这是我第一次使用 Fastify。 我想访问 Fastify 请求的未修改正文,以进行 Webhook 的签名验证 - 即,我希望看到请求传入时未被任
我是一名优秀的程序员,十分优秀!