有没有建议,谢谢。
# Gemfile
gem "anycable-rails", "~> 0.6.2"
gem "google-protobuf", "~> 3.7"
gem "jwt", "~> 2.1"
# Procfile
bundle exec anycable --server-command="anycable-go --headers=Upgrade,Host,Referer,User-Agent,X-Forwarded-For,X-Real-IP,X-Request-Id,Remote_addr,Origin,Connection,Authorization,Sec-WebSocket-Protocol,Sec-WebSocket-Key,Sec-WebSocket-Accept --host=localhost --port 3334"
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/assets/compiled/action_cable.min.js"></script>
<script type="application/javascript">
(function() {
this.App || (this.App = {});
App.initialize = (async () => {
const accessToken = await getToken();
ActionCable.INTERNAL.protocols.push(accessToken.auth.access_token);
return ActionCable.createConsumer("ws://localhost:3334/cable");
})();
}).call(this);
});
</script>
token = request.headers["HTTP_SEC_WEBSOCKET_KEY"].to_s.split(", ").last