Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整 server.before 触发点以及添加 process.exit 方法 #9

Merged
merged 2 commits into from
Dec 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions How-To-Write-A-Dora-Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ Methods:
- `middleware.after`
- `server.before`
- `server.after`
- `process.exit`

16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export default function createServer(_args) {
}));
_applyPlugins('middleware.after');

_applyPlugins('server.before');
const server = http.createServer(app.callback());
pluginArgs.server = server; // pass server to plugin
_applyPlugins('server.before');

server.listen(port, () => {
// Fix log, #8
const stream = process.stderr;
Expand All @@ -50,4 +52,16 @@ export default function createServer(_args) {
log.info('dora', `listened on ${port}`);
_applyPlugins('server.after');
});

process.on('exit', () => {
_applyPlugins('process.exit');
});

process.on('SIGINT', () => {
process.exit(0);
});

process.on('uncaughtException', () => {
process.exit(-1);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • process.exit 换成 exit ?
  • process.on 可以改成 process.once,这样不用担心注册多次

}