遇见 4 years ago
parent
commit
98a96113c3
  1. 6
      YuJian-Blog-Server/package-lock.json
  2. 2
      YuJian-Blog-Server/package.json
  3. 13
      YuJian-Blog-Server/router/index.js
  4. 13
      YuJian-Blog-Server/router/jwt.js

6
YuJian-Blog-Server/package-lock.json generated

@ -200,9 +200,9 @@ @@ -200,9 +200,9 @@
}
},
"express-jwt": {
"version": "5.3.3",
"resolved": "https://registry.npm.taobao.org/express-jwt/download/express-jwt-5.3.3.tgz",
"integrity": "sha1-5Ve0pj3TTF3datgUUnODhjFMwkM=",
"version": "6.0.0",
"resolved": "https://registry.npm.taobao.org/express-jwt/download/express-jwt-6.0.0.tgz",
"integrity": "sha1-IIhscwmD/7HHBqQ4MjXfhu/zSbg=",
"requires": {
"async": "^1.5.0",
"express-unless": "^0.3.0",

2
YuJian-Blog-Server/package.json

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
"cors": "^2.8.5",
"crypto": "^1.0.1",
"express": "^5.0.0-alpha.8",
"express-jwt": "^5.3.3",
"express-jwt": "6.0.0",
"express-validator": "^6.5.0",
"jsonwebtoken": "^8.5.1",
"mysql": "^2.18.1"

13
YuJian-Blog-Server/router/index.js

@ -1,14 +1,23 @@ @@ -1,14 +1,23 @@
const express = require("express");
const boom = require("boom");
const jwtAuth = require("./jwt");
const jwt = require("express-jwt");
const Result = require("../models/Result");
const userRouter = require("./user");
const ArticleRouter = require("./article");
const { PRIVATE_KEY } = require("../utils/constant");
const router = express.Router();
router.use(jwtAuth);
router.use(
jwt({
secret: PRIVATE_KEY,
algorithms: ["HS256"],
credentialsRequired: true,
}).unless({
path: ["/", "/user/login", "/article/list"],
})
);
router.get("/", (req, res) => {
res.send("Welcome Server");

13
YuJian-Blog-Server/router/jwt.js

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
const jwt = require("express-jwt");
const { PRIVATE_KEY } = require("../utils/constant");
module.exports = jwt({
secret: PRIVATE_KEY,
// 需要指定一个加密算法
// algorithms: ['HS256'],
credentialsRequired: true,
}).unless({
path: ["/", "/user/login", "/article/list"],
});
// 校验Token
Loading…
Cancel
Save