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

Vite middleware broken in v2 #845

Open
QuentinDutot opened this issue Jul 23, 2024 · 2 comments
Open

Vite middleware broken in v2 #845

QuentinDutot opened this issue Jul 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@QuentinDutot
Copy link

Environment

Operating System: MacOS
H3 Version: h3-nightly@2.0.0-1721661439.977db12
Package Manager: bun@1.1.16

Reproduction

bun run index.ts

import { serve } from 'bun'
import { createH3, fromNodeHandler, toWebHandler } from 'h3-nightly'
import { createServer } from 'vite'

const app = createH3({
  onError: console.error,
})

app.get('/', () => 'Hello World')

const vite = await createServer({
  server: { middlewareMode: true },
  appType: 'custom',
})

app.use(fromNodeHandler(vite.middlewares))

serve({ fetch: toWebHandler(app) })

Describe the bug

The server now returns an error 500 on any route.

1311 |   if (typeof handler !== "function") {
1312 |     throw new TypeError(`Invalid handler. It should be a function: ${handler}`);
1313 |   }
1314 |   return (event) => {
1315 |     if (!event.node) {
1316 |       throw new Error(
                       ^
error: [h3] Executing Node.js middleware is not supported in this server!

Additional context

No response

Logs

No response

@QuentinDutot QuentinDutot added the bug Something isn't working label Jul 23, 2024
@s3xysteak
Copy link

import { serve } from 'bun'

As I known, Vite is created based on Node.js.

@QuentinDutot
Copy link
Author

Yes, the Vite middleware is still a node connect instance

The fromNodeHandler function transforms the Node syntax (req, res) => {} into an h3 handler.
This handler should be able to run on any runtime and not just Node as stated in the docs

Runtime Agnostic
Your code will work on any JavaScript runtime including Node.js, Bun, Deno and Workers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants