mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 14:46:06 +08:00
开启jwt
This commit is contained in:
parent
2447ff21a5
commit
e376c70e7b
|
@ -65,27 +65,27 @@ export default ({ app }: { app: Application }) => {
|
|||
|
||||
app.use(bodyParser.json({ limit: '50mb' }));
|
||||
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
||||
// app.use(
|
||||
// auth(getTokenFromReq).unless({
|
||||
// path: excludePath,
|
||||
// }),
|
||||
// );
|
||||
// app.use((req, res, next) => {
|
||||
// if (req.url && excludePath.includes(req.path)) {
|
||||
// return next();
|
||||
// }
|
||||
// const data = fs.readFileSync(config.authConfigFile, 'utf8');
|
||||
// const authHeader = getTokenFromReq(req);
|
||||
// if (data) {
|
||||
// const { token } = JSON.parse(data);
|
||||
// if (token && authHeader.includes(token)) {
|
||||
// return next();
|
||||
// }
|
||||
// }
|
||||
// const err: any = new Error('UnauthorizedError');
|
||||
// err['status'] = 401;
|
||||
// next(err);
|
||||
// });
|
||||
app.use(
|
||||
auth(getTokenFromReq).unless({
|
||||
path: excludePath,
|
||||
}),
|
||||
);
|
||||
app.use((req, res, next) => {
|
||||
if (req.url && excludePath.includes(req.path)) {
|
||||
return next();
|
||||
}
|
||||
const data = fs.readFileSync(config.authConfigFile, 'utf8');
|
||||
const authHeader = getTokenFromReq(req);
|
||||
if (data) {
|
||||
const { token } = JSON.parse(data);
|
||||
if (token && authHeader.includes(token)) {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
const err: any = new Error('UnauthorizedError');
|
||||
err['status'] = 401;
|
||||
next(err);
|
||||
});
|
||||
app.use(config.api.prefix, routes());
|
||||
|
||||
app.use((req, res, next) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user