Files
JavaMyShop/node+vue/shop-bend/utils/ver.js
2024-09-27 01:16:36 +08:00

29 lines
1019 B
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const utils = require("./index")
const cache = require("../cache")
const config = require("../config")
module.exports = {
/**
* 路由拦截器拦截路由验证是否有token参数redis中是否已经有数据缓存
*/
async Verification(req, res, next) {
// 验证请求头是否包含token
if (req.headers.hasOwnProperty("token")) {
// 验证redis是否有缓存没有则去获取mysq然后缓存有直接读取缓存
if (await cache.Get(req.url) == null) {
req.unparams = utils.decrypted(req.headers.token)
next()
} else {
res.json({
status: config.dev.api.success,
cache: true,
data: await cache.Get(req.url)
})
}
} else {
res.json({
status: config.dev.api.CodeError,
data: "缺少必填参数请求头token"
})
}
}
}