Enable custom server entrypoints
This addresses and closes #428 (closed).
We've heard from many sources that the default server app.js (https://gitlab.coko.foundation/pubsweet/pubsweet/blob/master/packages/server/src/app.js) brings in a lot of things and is unwieldy in some situations. Ideally we'd reduce the number of things in app.js, but since it's hard-coded into server, it's difficult to play around with different designs without breaking the world.
I think this custom app approach will allow us to more quickly refine the default app.js, as well as enable more advanced use-cases (like using app.js for top level DI configuration, composition).
The way it works:
- You can add a
./server/app.js
file in your app's folder - You can configure a specific file in your config at
pubsweet-server.app
The simplest app.js
is something like this:
const configureApp = app => {
app.get('/verify', (req, res) => res.send('hi'))
// Actions to perform when the HTTP server starts listening
app.onListen = async server => {
// No-op
}
// Actions to perform when the server closes
app.onClose = async () => {
// No-op
}
return app
}
module.exports = configureApp
When you provide a custom app.js
, you're very much on your own in terms of what the server provides. The only thing the server does for you is start itself and start listening on a configured port.
Feedback welcome!