frontity
frontity copied to clipboard
Create a clean Koa application per request
trafficstars
This is part of the Server Extensibility feature. For full context please check out the final Implementation proposal.
To make sure that we don't leak middleware and app configuration from one request to another, my proposal is to create a new Koa application in each request.
Right now this is our @frontity/core/src/server export:
const server = ({ packages }) => {
// Create new app.
const app = new Koa();
// Configure the app...
app.use(/* ... */);
// Return the req/res function.
return app.callback();
};
We should switch to something like this:
const server = ({ packages }) => (req, res) => {
// Create a new app for each request.
const app = new Koa();
// Configure the app...
app.use(/* ... */);
// Return the final response.
return app.callback()(req, res);
};
Dependencies: none.
Relevant code:
https://github.com/frontity/frontity/blob/dev/packages/core/src/server/index.tsx
Assigning this first task over to me, planning on working on this in the next few days.
Awesome ๐ ๐ ๐