axe-me / vite-plugin-node

Vite plugin to run your node dev server with HMR!
989 stars 46 forks source link

h3 support? #79

Open lautiamkok opened 1 year ago

lautiamkok commented 1 year ago

Is it possible to support [unjs/h3](https://github.com/unjs/h3)? I tried the following code with the custom setup:

// ./app.ts
import { createServer } from 'node:http'
import { createApp, eventHandler, toNodeListener } from 'h3'

const app = createApp()
app.use(
  '/',
  eventHandler(() => 'Hello world!')
)

const listener = createServer(toNodeListener(app))

if (import.meta.env.PROD) {
  listener.listen(process.env.PORT || 3000)
  console.log(`🚀 Server ready at *:3000`)
}

export const viteNodeApp = listener

Error:

file:///...e/vite.config.ts.timestamp-1678018252429.mjs:16
        app(res, res);
        ^

TypeError: app is not a function

Any ideas?

axe-me commented 10 months ago

not very familiar with h3, but try expose the app instead the listener.
export const viteNodeApp = app