amark / gun

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

Websocket issue: WebSocket connection to 'ws://localhost:8765/gun' failed: #1278

Closed mertdeveci5 closed 2 years ago

mertdeveci5 commented 2 years ago

Everytime I run gun.js in the frontend of my application, I get the following error in the console of the browser:

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

The link changes to various different URLs and there is a new log with a new link every several seconds. Does anyone know the reason for this? Or do I have the incorrect configurations? Please see below for reference:

user.js

import Gun from "gun";
import "gun/sea";
import "gun/axe";
import { useAccount } from "wagmi";
import { createContext, useState } from "react";

export const db = Gun();

export const user = db.user().recall({ sessionStorage: true });

server.js

const express = require("express");
const app = express();
const Gun = require("gun");
const port = 5000;

app.use(Gun.serve);

const server = app.listen(port, () => {
  console.log(`Server running on port ${port}🔥`);
});

Gun({ web: server });
soulofmischief commented 2 years ago

@mertdeveci5 browsers need to import gun using import Gun from 'gun/gun', not import Gun from 'gun', to avoid running Node-specific code. More information here

Does this fix your issue?

mertdeveci5 commented 2 years ago

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

soulofmischief commented 2 years ago

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

ah yeah, I didn't even notice you didn't provide a URI for the relay. Without that, the apps don't know about each other. Are you using <address>/gun?

saiksaif commented 1 year ago

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

Hi, were you able to solve that? I'm facing the same issue in my sveltekit project and have no idea how to fix this can you help?