amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.08k stars 1.16k forks source link

[Question] Netx.js support? #1340

Open miguelbogota opened 11 months ago

miguelbogota commented 11 months ago

I'm currently working in a simple game and I want to implement a multiplayer mode. I would like to use Gun however I had found the documentation lacking on trending frameworks like Next.js, Solid, Qwik, ect... I tried to use it in a Next app just like the documentation said but I was bombed with a lot of issues in the terminal. I figured that the server and client versions were getting conflicted so I just add the scrips to the app like so:

Next.js 13

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/gun/axe.js"></script>
      </head>
      <body>{children}</body>
    </html>
  );
}

And augment the type definitions for typescript. This worked but another set of errors popped up.

WebSocket connection to 'ws://localhost:8765/gun' failed: 
WebSocket connection to 'ws://localhost:4000/gun' failed: 

I saw this other issue #1278 and it seems like I need to create a peer server but I and link the client and server for them to work. However, I do not want to create a single file for a server and every time I run my app run another terminar with the dev server or install unneeded dependencies to run 2 commands at the same time. I would like to use a Next.js api route to create the relay server but I do not know how to.

Can somebody help me to figure this out?

gustavcorpas commented 11 months ago

Hello fellow gun-enthusiast. I think we should keep the issues tab, for actual issues.

Consider asking questions over at: the gitter. The people there are usually very helpful :)