frontity icon indicating copy to clipboard operation
frontity copied to clipboard

Create a clean Koa application per request

Open SantosGuillamot opened this issue 4 years ago โ€ข 2 comments
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

SantosGuillamot avatar Feb 08 '21 12:02 SantosGuillamot

Assigning this first task over to me, planning on working on this in the next few days.

nicholasio avatar Mar 04 '21 16:03 nicholasio

Awesome ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ˜„

luisherranz avatar Mar 05 '21 08:03 luisherranz