onejs / one

❶ One is a new React framework - incredible for web, but also for native. No Metro, just a single Vite plugin.
https://onestack.dev
Other
2.98k stars 58 forks source link

Expose server instance for integration with graphql-ws #191

Open clayrisser opened 1 day ago

clayrisser commented 1 day ago

I need to setup a websocket server, and I need access to the server instance to create it.

https://github.com/enisdenjo/graphql-ws

For example...

import * as ws from "ws";

const wsServer = new WebSocketServer({
  onestackServerInstance,
  path: '/api/graphql',
});

How can I access the onestackServerInstance?

zetavg commented 1 day ago

Quick reply: In your vite.config.*, you can add a custom plugin with a configureServer hook to access the Vite dev server instance and extend its functionality.

const myServerPlugin = () => ({
  name: 'configure-server',
  configureServer(server) {
    // do something to the server
  },
})

export default defineConfig({
  plugins: [
    one(/* ... */),
    myServerPlugin(),
  ],
})

But I can think of a few issues that may make this unusable for your case:

I think we should take a deeper look soon, maybe tomorrow.