Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
E
egg-example
Project
Project
Details
Activity
Releases
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
shangbj
egg-example
Commits
d3b22d45
Commit
d3b22d45
authored
Sep 28, 2018
by
尚斌杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加中间件屏蔽Ip的练习
parent
9462befa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
forbidip.js
app/middleware/forbidip.js
+14
-0
printdate.js
app/middleware/printdate.js
+13
-0
config.default.js
config/config.default.js
+4
-2
No files found.
app/middleware/forbidip.js
0 → 100644
View file @
d3b22d45
'use strict'
;
module
.
exports
=
(
option
,
app
)
=>
{
return
async
function
forbidIp
(
ctx
,
next
)
{
const
forbidip
=
'192.168.146.169'
;
console
.
log
(
ctx
.
request
.
ip
);
if
(
ctx
.
request
.
ip
===
forbidip
)
{
ctx
.
status
=
403
;
ctx
.
body
=
'您的Ip已经被屏蔽'
;
}
else
{
await
next
();
}
};
};
app/middleware/printdate.js
0 → 100644
View file @
d3b22d45
'use strict'
;
/**
* @param {*} options 入参
* @param {*} app application实例
*/
module
.
exports
=
options
=>
{
// 返回一个异步的方法
return
async
function
priontDate
(
ctx
,
next
)
{
console
.
log
(
new
Date
(),
options
.
name
);
await
next
();
};
};
config/config.default.js
View file @
d3b22d45
...
...
@@ -7,8 +7,10 @@ module.exports = appInfo => {
config
.
keys
=
appInfo
.
name
+
'_1537794513145_4789'
;
// add your config here
config
.
middleware
=
[];
config
.
middleware
=
[
'printdate'
,
'forbidip'
];
config
.
printdate
=
{
name
:
'中间件'
,
};
// 模板引擎
config
.
view
=
{
mapping
:
{
...
...
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