[Next.js] Add Middleware to an API Route Created with next-connect
2023-09-14 09:00:45 时间
We'll learn how to create a middleware function for next-connect. This middleware will work at the route level, for example, for every request that hits the /api/next-connect-middleware endpoint, or at the HTTP verb level, GET /api/next-connect-middleware
import nextConnect from 'next-connect' const withAuthentication = (req, res, next) => { if (!req.headers.authentication) { return res.status(401).json({message: 'error'}) } return next() } const handler = nextConnect() .use(withAuthentication) .get(withAuthentication , (req, res) => res.json({message: 'get'})) export default handler
相关文章
- js如何获取iframe页面内的对象
- A2D JS框架 - Web API CSRF保护实现
- ExtJS简单的动画效果2(ext js淡入淡出特效)
- Knockout.Js官网学习(系列)
- [Mise] Refetch API data when a state value changes with the `$watch` property in Alpine JS
- [Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt
- [Node.js] Create a model to persist data in a Node.js LoopBack API
- [MEAN Stack] First API -- 1. with Node.js, Express and MongoDB
- js实现登录时记住用户名
- JS判断只能是数字和小数点
- [Mise] Refetch API data when a state value changes with the `$watch` property in Alpine JS
- [MEAN+ Webstrom] First API -- 2.Debug Node.js RESTful application
- JS 的新一代日期/时间 API Temporal
- atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js
- Atitit.跨语言反射api 兼容性提升与增强 java c#。Net php js
- atitit.js javascript 调用c# java php后台语言api html5交互的原理与总结p97
- js数组typeof后得到的类型是object??js如何判断数组是Array类型呢?
- 【Auto.js】使用Pro 8.0 API优化图色或无障碍的耗电问题
- 【Auto.js】QQ名片点赞
- html+css+js实现点球球小游戏
- QML 中常用的 JS 函数整理
- 如何使用 Node.js Stream API 减少服务器端内存消耗?
- 掌握JS压缩图片,这一篇就够了
- js json生取key,value 值
- js:使用正则RegExp实现字符串全部替换replaceAll
- js通过闭包实现多个相同事件只需绑定一次
- js-template-art【三】js api
- CSS(三)&JS(一)