首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下一步-连接TypeError:处理程序[(i++)]不是一个函数

下一步-连接TypeError:处理程序[(i++)]不是一个函数
EN

Stack Overflow用户
提问于 2021-09-23 10:52:24
回答 1查看 496关注 0票数 0

我试图使用'next-connect‘库在Next.js中实现路由->中间件->端点api方法。在我将.post()端点添加到下一个--connect之前,一切都很好。

代码语言:javascript
复制
// pages/api/index
import { protect, restrictTo, createUser } from 'api-lib/controllers/authController'
import { getAllUsers } from 'api-lib/controllers/userController'
import all from 'api-lib/middlewares/all';

const route = all() // next-connect instance with options privided

route.use(protect)             // rotect the route
     .use(restrictTo('admin')) // restrict the route to admin
     .get(getAllUsers)

export default route;

然后我添加了.post()端点

代码语言:javascript
复制
route.use(protect)             // rotect the route
     .use(restrictTo('admin')) // restrict the route to admin
     .get(getAllUsers)         // ---- works fine until here
     .post(createUser)         // !!! got error

得到了这个错误TypeError: handlers(i++)不是一个函数。

当我在另一条路径中测试createUser函数时,它正确地工作了。

有什么建议吗?会不会是“下一个连接”的错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-24 07:54:52

我发现了问题。实际上,我错误地从一个错误的文件导入了createUser

变化

代码语言:javascript
复制
// pages/api/index
import { protect, restrictTo, createUser } from 'api-lib/controllers/authController'
import { getAllUsers } from 'api-lib/controllers/userController'

代码语言:javascript
复制
// pages/api/index
import { protect, restrictTo } from 'api-lib/controllers/authController'
import { getAllUsers, createUser } from 'api-lib/controllers/userController'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69298620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档