Skip to content

Commit

Permalink
fix: Cleanly exit node process (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 authored Jul 21, 2022
1 parent d825db6 commit ff9d0b5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,13 @@ export default class HttpServer {
log.notice()
log.notice('Enter "rp" to replay the last request')

process.openStdin().addListener('data', (data) => {
// note: data is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then trim()
if (data.toString().trim() === 'rp') {
this.#injectLastRequest()
}
})
process.stdin.addListener('data', this.#handleStdin)
}

// stops the server
stop(timeout) {
process.stdin.removeListener('data', this.#handleStdin)
process.stdin.pause()
return this.#server.stop({
timeout,
})
Expand All @@ -226,6 +221,15 @@ export default class HttpServer {
}
}

#handleStdin = (data) => {
// note: data is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then trim()
if (data.toString().trim() === 'rp') {
this.#injectLastRequest()
}
}

#logPluginIssue() {
log.notice(
'If you think this is an issue with the plugin please submit it, thanks!\nhttps://github.com/dherault/serverless-offline/issues',
Expand Down

0 comments on commit ff9d0b5

Please sign in to comment.