It'd be ideal if we could just assume that the server is running in a vacuum where the only thing it needs to do is to handle req/res cycles.
But servers don't live in isolation - they are in dev/test/prod environments, they may or may not have reverse proxies (all of which have varying features at differing price points), deployed in bare machine/containers/by an orchestrator, etc.
And to account for the various environments and their features, we need a way to systematically plug in various middlewares with different conditions and orders.
Some of the middlewares that should be optional include:
URL rewriting, such as HTTP=>HTTPS, www=>non-www, trailing slash, etc (important if doing SSR and/or if the server is NOT behind a reverse proxy, e.g. Heroku)
rate-limiting! (a lot of API gateways/reverse proxies can handle this)
gzip compression (ditto)
logging, specifically request logging
circuit breaker
caching (oh boy)
metrics (newrelic/prometheus/various health check middlewares)
dashboards (e.g. for bull queue, express-status-monitor)
...and the list goes on.
Honestly, this shit makes me want to just swap to Fastify and use their plugin architecture (especially because of the order these middlewares need to be plugged in), but surely there must be a way to do this cleanly in express, right? (especially using the CENTRAL configuration system that I have already setup)
It'd be ideal if we could just assume that the server is running in a vacuum where the only thing it needs to do is to handle req/res cycles.
But servers don't live in isolation - they are in dev/test/prod environments, they may or may not have reverse proxies (all of which have varying features at differing price points), deployed in bare machine/containers/by an orchestrator, etc.
And to account for the various environments and their features, we need a way to systematically plug in various middlewares with different conditions and orders.
Some of the middlewares that should be optional include:
...and the list goes on.
Honestly, this shit makes me want to just swap to Fastify and use their plugin architecture (especially because of the order these middlewares need to be plugged in), but surely there must be a way to do this cleanly in express, right? (especially using the CENTRAL configuration system that I have already setup)