Hi @luisherranz, great IP! This will make Frontity amazingly extensible.
-
Order of middleware execution.
While reading through the details noticed that there is no guarantee of the order of middleware execution. Do you think this is important? Would this be something that folks would expect? -
Escape hatch by exposing only the
app
.
While having aserver
property itās pretty explicit and it makes a clear separation between what part of the app itās involving, have you thought about having this kind of api? This practically will be called after thebeforeSSR
.
export default {
server: {
myPackage: ({ app }) => {
// Sample of a middleware code
app.use((ctx, next) => {
const store = ctx.store;
// At this point the `store` is available and it can do anything it wants with it.
});
},
},
};
- Allow interrupting the render flow.
Open Questions: We need to find a way to allow packages to āskip React SSRā so they can return other responses for URLs that should not be managed by React.
If we would allow the api at point #2 this will turn into simply handle the response on the server. Like this: https://codesandbox.io/s/bold-feistel-4og51?file=/index.js
Example:
export default {
server: {
myPackage: ({ app }) => {
// Custom `/api` endpoint
app.use((ctx, next) => {
if (ctx.url.startsWith('/api')) {
// Serialize the state, or other API responses, auth
ctx.body = JSON.stringify(ctx.store.state, null, 2);
return;
}
await next();
});
},
},
};
If I am not mistaken @cristianbote is currently refactoring the core middleware. Cristian, could you please leave a message with the status of that refactoring? Thanks
Yup! I am done with it. The changes can be seen here: https://github.com/frontity/frontity/pull/687/files#diff-2aa5d096a9b58e6ba83f934e3f72bcff6ab4f27ca5cfe05dde74fe087ab53df5R93-R100.
At this point the store
and settings
are exposed on ctx.state
but itās not something that my implementation relies on so we can redefine those at will.
I am confident that allowing and exposing a function instead of a dictionary with middlewares, will empower the developers to extend at will the server as they wish.
What do you think @luisherranz? Did something slipped through my mind?