-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Discussion] universal-middleware/hono #26
Comments
@fortezhuo Does magne4000/universal-middleware#75 answer your question? @magne4000 Maybe we can start documenting
Happy to help if you feel like you need a fresh perspective on it. |
Hm.. I still don't get how to use native behavior like c.var and c.set ? Maybe documentation with more examples will be great for better understanding |
@fortezhuo the "right" way to do that is with import { type Get, type UniversalMiddleware } from "@universal-middleware/core";
// This lacks documentation, I'll fix this
import { createMiddleware } from "@universal-middleware/hono";
import { getCookie } from "@universal-middleware/core/cookie";
const preference = (() => (request, context, runtime) => {
// Update Context
return {
...context,
preference: getCookie(request, "preference"),
// ...
}
}) satisfies Get<[], UniversalMiddleware>;
// universal Context is automatically applied to `pageContext`
instance.use(createMiddleware(preference)()) NOTE:
@brillout Started discussion magne4000/universal-middleware#76
👍 You're absolutely right. I'm on it |
If the user wants to stay flexible about his server framework choice, then I agree. If the user loves hono and wants everything to be hono, then I guess the right way is to always use Hono utilities instead of |
I guess so? That would be a good reason to add back
I think that if the chosen server can be deployed somewhere, using non universal middlewares shouldn't cause any issue. |
I was mentioning this a little bit last time we talked about it: my idea is that once vikejs/vike#1268 is implemented the user will never have to add things to So I think we don't need to revive the
I guess Hono can be deployed anywhere. But Express.js cannot (and/or shouldn't) so maybe we should, eventually, add some kind of warning for Express.js in the future (maybe in Bati). |
I second that, a "portable" tag (like we have for "bleeding edge") could be great. |
Love it. |
Maybe we should systematically add everything 🤔 I guess it's always nice if the user can access everything, otherwise |
Thanks for reply. Currently I fallback and use 0.1.x version instead, and I hope using |
@magne4000 WDYT? |
@fortezhuo We will revive the |
@fortezhuo |
export const ssr = () =>
vikeNode({
pageContext: (runtime: RuntimeAdapter) => {
const c = runtime.hono;
return {
preference: c.var.preference,
user: c.var.user,
vendor: c.var.vendor,
}
},
static: {
root: distClient,
},
}) |
@magne4000 How about this: app.use(
vike({
- pageContext(runtime: RuntimeAdapter) {
+ pageContext(runtime) {
return {
user: runtime.req.user
}
}
})
) And we add a note mentioning what Alternatively, we add a page at |
We'll start with this. If the need arises, I'll add those details in |
Actually it will either bloat the README, or be too much confusing that way, I'll document |
Note added with link to |
Maybe we can make it a separate second note |
That is FYI if you have a middleware returning some JS object like
|
Assuming the user doesn't directly use |
Removing the ref to the universal Context would be less confusing indeed. But I just realized that currently, the universal context AND the runtime are spread into the |
Hm, good question. Maybe both... it's kind of the philosophy behind vikejs/vike#1268. But, yea, it's probably easier if we start with |
Would you rather wait for the next breaking change to add this refacto (as it's also a breaking change, even if not properly documented)? I think that can wait, and I can just remove the universal context reference for now |
Personally, I think we can introduce that little breaking change as a patch, without bumping the minor. I don't think any user uses it. Actually, we could argue we didn't mention it so far so it wasn't part of the stable api 😁 But as you wish, no hard preferences on this. |
I don't think anyone uses it either, so #33 |
|
I still don't get about universal middleware.
I have code like this using hono
And with universal-middleware, can I still use hono context using native behavior like
c.var
andc.set
?The text was updated successfully, but these errors were encountered: