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

How to use vite.createServer with Bun.serve? #12212

Open
Blankeos opened this issue Jun 27, 2024 · 1 comment
Open

How to use vite.createServer with Bun.serve? #12212

Blankeos opened this issue Jun 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Blankeos
Copy link

What is the problem this feature would solve?

Since Bun.serve doesn't have http.Incoming and http.ServerResponse, I'm wondering how to implement an equivalent of this Node code in Bun.

In Node:

import { Hono } from 'hono'
import { serve, type HttpBindings } from '@hono/node-server'
import type { ViteDevServer } from 'vite'

const base = process.env.BASE || '/'

const app = new Hono<{ Bindings: HttpBindings }>()

let vite: ViteDevServer
if (!isProduction) {
    const { createServer } = await import('vite')
    vite = await createServer({
        server: { middlewareMode: true },
        appType: 'custom',
        base
    })
    app.use(async (c, next) => {
        const viteDevMiddleware = () => new Promise<void>((resolve) => {
            vite.middlewares(c.env.incoming, c.env.outgoing, () => resolve())
        });
        await viteDevMiddleware()
        await next()
    })
}

serve({
    fetch: app.fetch,
    port
});

What is the feature you are proposing to solve the problem?

Maybe an adapter for Bun.serve with http.Incoming and http.ServerResponse if it's possible?

What alternatives have you considered?

No response

@Blankeos Blankeos added the enhancement New feature or request label Jun 27, 2024
@huseeiin
Copy link
Contributor

this is not an issue in bun. you cannot use connect middleware directly with Bun.serve. you should use express or polka or fastify with @fastify/middie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants