WebSocket握手时出错:意外响应代码:200-Next.js、Gun.js、ZEIT Now

WebSocket握手时出错:意外响应代码:200-Next.js、Gun.js、ZEIT Now,next.js,gun,vercel,Next.js,Gun,Vercel,我现在通过ZEIT获得了一个Gun.js+Next.js应用程序(源代码),我从Chrome和Safari中得到了以下错误: WebSocket connection to 'wss://maptivist.randymorantes.now.sh/' failed: Error during WebSocket handshake: Unexpected response code: 200 从Firefox我得到: Firefox can’t establish a connection

我现在通过ZEIT获得了一个Gun.js+Next.js应用程序(源代码),我从Chrome和Safari中得到了以下错误:

WebSocket connection to 'wss://maptivist.randymorantes.now.sh/' failed: Error during WebSocket handshake: Unexpected response code: 200
从Firefox我得到:

Firefox can’t establish a connection to the server at wss://maptivist.randymorantes.now.sh/.
此外,我的枪友之间似乎没有交流,可能是因为这个错误。我想这可能是,但我不知道如何将各种解决方案应用到我的案例()。相关代码似乎是:

// in next.config.js

const nextConfig = {
  target: 'serverless',
  webpack: customWebpackConfig,
  workboxOpts: {
    swDest: 'static/service-worker.js',
    runtimeCaching: [
      {
        urlPattern: /^https?.*/,
        handler: 'NetworkFirst',
        options: {
          cacheName: 'https-calls',
          networkTimeoutSeconds: 15,
          expiration: {
            maxEntries: 150,
            maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
          },
          cacheableResponse: {
            statuses: [0, 200],
          }
        }
      }
    ]
  }
}
问题还可能是我如何使用枪(浓缩):

我的理解是,在创建用户时,我的两个对等方应该通过位于我URL的第三个对等方自动同步这些更改。但是,虽然使用了一个URL(
const gun=gun()https://gunjs.herokuapp.com/gun)
),使用两个(
var gun=gun([]http://localhost:8765/gun', 'https://gunjs.herokuapp.com/gun)
)。因此,对于我的用例,我不清楚是否还需要传递一个与本地机器对应的URL

我尝试过的URL组合(在重新部署和刷新之后)(还不清楚是否需要在URL中附加“/gun”或约定):


我被难住了。请帮忙!:-)

@randy morantes ZEIT支持WebSocket吗?如果是这样,这应该是可行的

我猜你需要枪

GUN在ZEIT服务器上运行吗?看起来不像。你能粘贴你的服务器ZEIT代码吗

浏览器不需要
localhost
在本地运行GUN,它将直接在浏览器中运行GUN。但是,开发人员/用户也可以在本地运行GUN-in-NodeJS(与浏览器分开),这就是
localhost
所引用的,除非本地运行的GUN-NodeJS对等节点处于活动状态(这不太可能)


您可能会在友好社区聊天中获得更直接的帮助,但请记住回到这里,用您学到的内容更新您的帖子和答案,以便其他人也能从中受益。:)

我没有服务器代码,这就是问题所在<代码>常数枪=枪('https://gunjs.herokuapp.com/gun)让它工作起来,也消除了我的误解。我现在明白了,Gun客户机/对等机必须在某个点连接到至少一个运行Gun的服务器/超级对等机,以持久化数据,并(我认为)促进WebRTC连接(关于这方面的文档可能更清晰)。谢谢你的帮助!
import Gun from 'gun/gun'
import 'gun/sea'

const gun = Gun('https://maptivist.randymorantes.now.sh')
const user = gun.user()

user.create(valueAlias, valuePassword, response => {
  if (!response.err) {
    gun.get('users').set(user)
  }
})

// Only one user is found, the current user, despite there being
// two different users signed in on different devices.
gun.get('users').map(user => {
  console.log('user: ', user)
})
const gun = Gun('https://maptivist.randymorantes.now.sh')
const gun = Gun('https://maptivist.randymorantes.now.sh/gun')
const gun = Gun(['http://localhost:3000/', 'https://maptivist.randymorantes.now.sh'])
const gun = Gun(['http://localhost:3000/', 'https://maptivist.randymorantes.now.sh/gun'])
const gun = Gun(['http://localhost:3000/gun', 'https://maptivist.randymorantes.now.sh/gun'])