Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mp_estate_server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mp_estate_backstage
mp_estate_server
Commits
a1d98da3
Commit
a1d98da3
authored
Sep 03, 2020
by
成旭东
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
71ff67ce
Pipeline
#27896
passed with stage
in 1 minute 50 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
27 deletions
+13
-27
jwtMiddle.ts
app/middleware/jwtMiddle.ts
+3
-15
router.ts
app/router.ts
+4
-4
config.default.ts
config/config.default.ts
+6
-8
No files found.
app/middleware/jwtMiddle.ts
View file @
a1d98da3
...
...
@@ -4,28 +4,16 @@ module.exports = (options: any) => {
return
async
function
(
ctx
:
Context
,
next
:
any
)
{
// 拿到传会数据的header 中的token值
const
token
=
ctx
.
request
.
header
.
authorization
;
// const method = ctx.method.toLowerCase();
// if (options.exclude && options.exclude.includes(ctx.path)) {
// await next();
// return;
// }
if
(
options
.
exclude
&&
options
.
exclude
.
some
((
item
:
any
)
=>
item
.
split
(
'/'
)[
2
]
===
ctx
.
path
.
split
(
'/'
)[
2
]))
{
if
(
options
.
exclude
&&
options
.
exclude
.
includes
(
ctx
.
path
))
{
await
next
();
return
;
}
// 当前请求时get请求,执行接下来的中间件
if
(
!
token
)
{
ctx
.
throw
(
401
,
'未登录, 请先登录'
);
}
else
{
try
{
// 解码token
ctx
.
app
.
jwt
.
verify
(
token
.
split
(
' '
)[
1
],
ctx
.
app
.
config
.
jwt
.
secret
);
await
next
();
}
catch
(
e
)
{
ctx
.
throw
(
401
,
'登录失效'
);
}
}
await
next
();
};
};
app/router.ts
View file @
a1d98da3
import
{
Application
}
from
'egg'
;
export
default
(
app
:
Application
)
=>
{
const
{
controller
,
router
,
jwt
}
=
app
;
const
{
controller
,
router
}
=
app
;
router
.
post
(
'/api/login'
,
jwt
,
controller
.
user
.
index
.
login
);
router
.
get
(
'/api/session'
,
jwt
,
controller
.
user
.
index
.
session
);
router
.
get
(
'/api/session/menus'
,
jwt
,
controller
.
user
.
index
.
menus
);
router
.
post
(
'/api/login'
,
controller
.
user
.
index
.
login
);
router
.
get
(
'/api/session'
,
controller
.
user
.
index
.
session
);
router
.
get
(
'/api/session/menus'
,
controller
.
user
.
index
.
menus
);
router
.
post
(
'/api/upload/media'
,
controller
.
util
.
uploadMedia
);
// 新房房源管理
...
...
config/config.default.ts
View file @
a1d98da3
...
...
@@ -33,16 +33,14 @@ export default (appInfo: { name: string; }) => {
config
.
middleware
=
[
'errorHandler'
,
'pagination'
,
//
'jwtMiddle',
'jwtMiddle'
,
];
// config.jwtMiddle = {
// exclude: [
// '/api/login',
// '/api/upload/**',
// '/api/estate/**',
// ],
// };
config
.
jwtMiddle
=
{
exclude
:
[
'/api/login'
,
],
};
config
.
jwt
=
{
secret
:
'123456'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment