mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-06 08:27:54 +08:00
接口文档整理
This commit is contained in:
parent
6d1d88e7f5
commit
95a964f000
@ -13,6 +13,12 @@ npm run dev
|
||||
## Swagger文档访问地址
|
||||
http://localhost:3000
|
||||
|
||||
## 在swagger中添加token验证
|
||||
① 先请求验证码接口,拿到验证码(info字段就是验证码)
|
||||
② 然后请求登录接口,你可以在网页的Network中拿到登录成功后返回的token,复制
|
||||
③ 最后回到swagger,点击右上角的绿色边框Authorize,你会看到一个Value的输入框,将复制的token前面加上Bearer 粘贴上去,点确定即可(Authorize)
|
||||
(注意Bearer后面有一个空格哦)
|
||||
|
||||
## 注意点
|
||||
请先全局安装typescript、ts-node,如安装请忽略
|
||||
```
|
||||
|
@ -153,6 +153,14 @@ const register = async (req: Request, res: Response) => {
|
||||
const updateList = async (req: Request, res: Response) => {
|
||||
const { id } = req.params
|
||||
const { username } = req.body
|
||||
let payload = null
|
||||
try {
|
||||
const authorizationHeader = req.get("Authorization")
|
||||
const accessToken = authorizationHeader.substr("Bearer ".length)
|
||||
payload = jwt.verify(accessToken, secret.jwtSecret)
|
||||
} catch (error) {
|
||||
return res.status(401).end()
|
||||
}
|
||||
let modifySql: string = 'UPDATE users SET username = ? WHERE id = ?'
|
||||
let sql: string = 'select * from users where id=' + id
|
||||
connection.query(sql, function (err, data) {
|
||||
@ -160,7 +168,7 @@ const updateList = async (req: Request, res: Response) => {
|
||||
if (err) {
|
||||
Logger.error(err)
|
||||
} else {
|
||||
let modifyParams = [username, id]
|
||||
let modifyParams: string[] = [username, id]
|
||||
// 改
|
||||
connection.query(modifySql, modifyParams, async function (err, result) {
|
||||
if (err) {
|
||||
@ -323,7 +331,7 @@ const captcha = async (req: Request, res: Response) => {
|
||||
})
|
||||
generateVerify = Number(create.text)
|
||||
res.type('svg') // 响应的类型
|
||||
res.json({ code: 1, msg: create.text, svg: create.data })
|
||||
res.json({ code: 1, info: create.text, svg: create.data })
|
||||
}
|
||||
|
||||
export {
|
||||
|
@ -58,4 +58,4 @@ app.listen(config.port, () => {
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
// open(`http://localhost:${config.port}`) // 自动打开默认浏览器
|
||||
open(`http://localhost:${config.port}`) // 自动打开默认浏览器
|
Loading…
x
Reference in New Issue
Block a user