Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
yyq
7 years ago
Commit
bb6185e84204174ab6ecb045a9db5f42a6be5afa
1 parent
e16f78f9
path decode
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
doraemon/middleware/path-decode.js
doraemon/middleware/path-decode.js
0 → 100644
View file @
bb6185e
/**
* 处理伪静态化路由编码中间中间件
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/12/26
*/
const
urlEncode
=
require
(
'urlencode'
);
const
_
=
require
(
'lodash'
);
module
.
exports
=
()
=>
{
return
(
req
,
res
,
next
)
=>
{
let
path
=
req
.
path
;
if
(
!
req
.
xhr
&&
_
.
indexOf
(
path
,
'%'
)
>
-
1
)
{
try
{
req
.
url
=
decodeURIComponent
(
path
);
}
catch
(
e
)
{
try
{
req
.
url
=
urlEncode
.
decode
(
path
,
'gb2312'
);
}
catch
(
e1
)
{
return
next
();
}
}
}
return
next
();
}
};
...
...
Please
register
or
login
to post a comment