const Entrypoint = require('@pm2/pm2.io').Entrypoint
class App extends Entrypoint {
// The .onStart is called by Entrypoint when initializing the app
onStart(cb) {
this.server = http.createServer((req, res) => {
res.send('Hello')
})
// The cb send process.send('ready') to PM2
// if we manage to retrieve the http instance we could bind it to
// https://github.com/hunterloftis/stoppable
this.server.listen(8000, cb)
}
// The .onStop is called when the app will exit (exception, rejection, sigint, sigstop...)
onStop(cb) {
}
// Just a method to cleanly list metrics
metrics() {
this.meter('stuff-metrics', () => {
return 42
})
}
// To cleanly list diagnostics
diagnostics() {
this.on('getEnv', (cb) => {
cb(null, process.env)
})
}
}
module.exports = new Entrypoint
// wait_ready? listen_timeout? kill_timeout? // this.io.waitFor('app') pour onStart demare app // auto require de pm2 lightweight // ipc pubsub
This is a simple draft, based on my intuition, @vmarchaud @wallet77 feedback welcome on this api design