refactor(app): 重构应用并添加开发脚本
- 移除了登录路由 - 添加了 nodemon 开发脚本 - 引入了 nodemon 依赖 - 在 verifyThirdPartyToken 中添加了日志输出
This commit is contained in:
7
app.js
7
app.js
@@ -33,13 +33,6 @@ router.get("/public", (ctx) => {
|
|||||||
ctx.body = "Public content";
|
ctx.body = "Public content";
|
||||||
});
|
});
|
||||||
|
|
||||||
// 登录路由
|
|
||||||
router.post("/login", (ctx) => {
|
|
||||||
const user = { id: 1, username: "admin" };
|
|
||||||
const token = jwt.sign(user, process.env.JWT_SECRET, { expiresIn: "1h" });
|
|
||||||
ctx.body = { token };
|
|
||||||
});
|
|
||||||
|
|
||||||
// 自定义中间件:解析并验证第三方Token
|
// 自定义中间件:解析并验证第三方Token
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
const authHeader = ctx.headers.authorization;
|
const authHeader = ctx.headers.authorization;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js"
|
"start": "node app.js",
|
||||||
|
"dev": "nodemon app.js"
|
||||||
},
|
},
|
||||||
"author": "kubbo",
|
"author": "kubbo",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
"koa": "^2.15.4",
|
"koa": "^2.15.4",
|
||||||
"koa-bodyparser": "^4.4.1",
|
"koa-bodyparser": "^4.4.1",
|
||||||
"koa-jwt": "^4.0.4",
|
"koa-jwt": "^4.0.4",
|
||||||
"koa-router": "^13.0.1"
|
"koa-router": "^13.0.1",
|
||||||
|
"nodemon": "^3.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user