-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+middleware example with @universal-middleware/router #2050
base: main
Are you sure you want to change the base?
Conversation
const middlewares = (await getMiddlewares()) as (RouteDefinition | MiddlewareDefinition)[] | ||
const router = new UniversalRouter() | ||
apply(router, middlewares) | ||
app.all('*', createMiddleware(() => router[universalSymbol])()) | ||
// TODO replace with UniversalExpressRouter once done. | ||
// It should look like this: | ||
// const router = new UniversalExpressRouter(app) | ||
// apply(router, middlewares) | ||
// So no need for manually calling app.*, and rely on express routing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved to vike-node
, which would be responsible to create the proper Universal*Router
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 And eventually vike-{express,hono,...}
so that one Vike extension = one tool (e.g. to fit the text next to the landing page's slot machine).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. I'm currently working on the Vike CLI and one neat thing we could eventually do is to have vike-express
have a built-in Express.js server boilerplate, so that the user doesn't have to write a single line of server code (but the user can eject that server boilerplate if he needs to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be simple enough, and I like the idea.
I can see that in Bati we would then just add a comment somewhere or a paragraph in the README to explain that it can be ejected.
We could even allow the user to retrieve the built-in express like this:
import { app } from "vike-express";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We could even allow the user to retrieve the built-in express like this:
Neat idea ✨
I wonder whether/how we can add a name to a universal middleware, so that users can selectively remove middlewares. Use case: user is using |
I was thinking about that with the same use case in mind. IMO the best solution would be to be able to just eject the +middleware, but I think we're not there yet. |
Yea, I think a |
Some documentation around the |
Neat 😍 |
WIP around how we can move some logic used in
+middleware.ts
process touniversal-middleware
.@brillout This is mostly to discuss what we should port to
universal-middleware
and create a proper API.universal-middleware
in progress PR: magne4000/universal-middleware#95