小编Cur*_*dix的帖子

Rails + ActionCable + Passenger + AWS Elasticache (Redis):如何修复“WebSocket 在建立连接之前关闭”的问题。生产上?

我在生产环境中使用操作电缆时遇到一些麻烦。开发环境工作正常。

要解决的错误: 与“wss://myapp.com/cable”的 WebSocket 连接失败:WebSocket 在建立连接之前已关闭。

我在 Chrome 的控制台上多次收到此错误。

  • 红宝石2.3.0
  • 导轨 5.0.7.2
  • nginx 1.10.1
  • 客运5.0.30
  • Redis 5.0.3(在 AWS Elasticache 上)

nginx.conf

server {
  listen 443 ssl;
  server_name myapp.com *myapp.com;
  root /home/ubuntu/myapp/current/public;
  ssl_certificate ...;
  ssl_certificate_key ...;
  passenger_enabled on;
  passenger_min_instances 1;
  ...

  location /cable {
    passenger_app_group_name my_app_action_cable;
    passenger_force_max_concurrent_requests_per_process 0;
  }
}
Run Code Online (Sandbox Code Playgroud)

电缆.yml

production:
  adapter: redis
  url: redis://myapp.grzdsm.0001.euw1.cache.amazonaws.com:6379
Run Code Online (Sandbox Code Playgroud)

生产.rb

config.action_cable.url = "wss://myapp.com/cable"
config.action_cable.allowed_request_origins = ["https://myapp.com", "myapp.com"]
Run Code Online (Sandbox Code Playgroud)

路线.rb

mount ActionCable.server => '/cable'
Run Code Online (Sandbox Code Playgroud)

notification_channel.rb

class NotificationChannel < ApplicationCable::Channel

  def subscribed
    stream_from "notification"
  end …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails passenger websocket actioncable

6
推荐指数
1
解决办法
997
查看次数

Web3.js getBalance 始终显示 0

我想获取我的以太坊钱包余额,因此我使用 web3.js 制作了一个应用程序,并创建了一个使用 go-ethereum 运行的以太坊节点。

我的钱包里有一些以太币,并且节点已同步,但我的余额始终显示 0 以太币。

这是我的应用程序:

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
balance = web3.eth.getBalance('0x...');
console.log(balance);
Run Code Online (Sandbox Code Playgroud)

使用以下命令启动节点:

geth --rpc --rpccorsdomain "*"
Run Code Online (Sandbox Code Playgroud)

web3.js 节点的状态:

API Version : 0.19.0
Node Version : Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9.1
Network Version : 1
Ethereum Version : 63
isConnected : true
{host: "http://localhost:8545", timeout: 0}
Listening : true
Peer Count : 25
{currentBlock: 4507134, highestBlock: 4507228, knownStates: 6019923, pulledStates: 6004673, startingBlock: 4506690}
Run Code Online (Sandbox Code Playgroud)

当我获取交易时

web3.eth.getTransaction('0x..')
Run Code Online (Sandbox Code Playgroud)

我可以在我的钱包上看到一些以太币的转账。当我检查 etherscan 时,我的钱包里仍然有这些以太币,但 web3.js 的余额仍然返回 0。

当我检查最后一个块时: …

ethereum web3js go-ethereum

4
推荐指数
1
解决办法
3229
查看次数