diff --git a/How-To-Write-A-Dora-Plugin.md b/How-To-Write-A-Dora-Plugin.md index 9ddbc57..f884823 100644 --- a/How-To-Write-A-Dora-Plugin.md +++ b/How-To-Write-A-Dora-Plugin.md @@ -42,4 +42,5 @@ Methods: - `middleware.after` - `server.before` - `server.after` +- `process.exit` diff --git a/src/index.js b/src/index.js index bb6f7b6..1e384f0 100644 --- a/src/index.js +++ b/src/index.js @@ -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; @@ -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); + }); }