我已经通过 ZEIT Now部署了一个 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/.
此外,我的 Gun 同行似乎没有相互交流,可能是因为这个错误。我认为这可能是我的服务器配置的问题,但我不知道如何将各种解决方案应用于我的案例(示例)。相关代码似乎是:
// 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],
}
}
}
]
}
}
问题也可能是我如何使用 Gun(浓缩):
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)
})
我的理解是,在创建用户时,我的两个对等点应该通过位于我的 URL 的第三个对等点自动同步这些更改。但是,虽然Gun + Next 示例使用一个 URL ( const gun = Gun('https://gunjs.herokuapp.com/gun')
),但Gun todos 示例使用两个 ( var gun = Gun(['http://localhost:8765/gun', 'https://gunjs.herokuapp.com/gun'])
)。因此,我不清楚,对于我的用例,我是否还需要传递与我的本地计算机对应的 URL。
我尝试过的 URL 组合(在重新部署和刷新之后)(还不清楚是否需要将“/gun”附加到 URL 或约定):
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'])
我难住了。请帮忙!:-)