Skip to content
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

Use universal-middleware #16

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

magne4000
Copy link
Member

@magne4000 magne4000 commented Oct 9, 2024

Notable changes

  • Use @universal-middleware/compress for compression
  • All cache related features have been dropped
  • getPageContext hook is removed. The whole context from universal middlewares is given as a Context to renderPage. This means that the same effect can be achieved by any custom universal middleware.
  • No more distinction between node and non-node envs (at least for now 🤞)

Next steps (not in this PR)

  • Put cache feature back?
  • Is it possible to have some generic way to handle HMR websocket connections, perhaps with crossws?

@jasonhilldm
Copy link

jasonhilldm commented Oct 14, 2024

Hi. I stumbled across this extension while trying to figure out the best way to deploy to Node and it looks awesome. The one issue I have is that I am using Auth.js for authentication and was previously using universal middleware to add the logged in user to the context.

When I use the vike-node extension though, my modified context is not being seen by Vike so I assume it's using a different context. I'm assuming these draft changes will mean my context changes will be seen by Vike via the use of universal middleware...is that right?

Not sure how far away these changes are, but is there another way that I can add the user to the context using regular middleware so that Vike will see that when I am using vike-node?

@magne4000
Copy link
Member Author

@jasonhilldm I would suggest to wait for this PR to be finished, as it will fix your issue.
Nevertheless, you could still retrieve the context for your server using the getContext function of your server inside the pageContext hook. Something like this should do the trick (untested, and probably does not work for all servers):

import { getContext } from "@universal-middleware/hono";

app.use(
  vike({
    pageContext: (req) => getContext(req)
  })
)

@jasonhilldm
Copy link

Thank you - that worked perfectly.

@magne4000 magne4000 force-pushed the magne4000/universal-middleware branch from 05aa8d6 to 775df55 Compare October 16, 2024 10:10
@magne4000 magne4000 marked this pull request as ready for review October 16, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants