我使用angular-actioncable在我們的 rails 后端和 angularjs 前端實作了動作電纜,一切都按預期作業,建立了客戶端到服務器的 websocket 連接并且廣播和接收正在作業,但是當我啟動應用程式時,它總是拋出一個 rack lint 錯誤以及 GET /cable 上的 500 錯誤,
09:33:10 web.1 | Rack::Lint::LintError: Status must be >=100 seen as integer
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:25:in `assert'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:675:in `check_status'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:70:in `_call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:42:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:253:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/chunked.rb:98:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/content_length.rb:17:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:632:in `process_client'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:728:in `worker_loop'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:548:in `spawn_missing_workers'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:144:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/bin/unicorn:128:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:476:in `exec'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:24:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `<main>'
09:33:10 web.1 | 127.0.0.1 - - [11/Feb/2022:09:33:10 1100] "GET /cable/ HTTP/1.1" 500 3356 0.4378
我將列印件放在機架 gem 中,它回傳狀態為 -1,找不到任何關于 -1 含義的檔案。
謝謝
uj5u.com熱心網友回復:
對于其他有同樣問題的人,原因是 Rack 在將 http 協議升級到 websockets 時進行套接字劫持并回傳一個 -1,機架 lint 不認為這是一個有效的 http 狀態,在開發中你可以設定RACK_ENV=deployment RAILS_ENV=development為測驗并且你可以用一個簡單的初始化程式存根標頭/狀態檢查以檢查動作電纜,更多細節在這里,來自上面鏈接的初始化程式,
class ::Rack::Lint
alias check_status_orig check_status
alias check_headers_orig check_headers
alias check_content_type_orig check_content_type
alias check_content_length_orig check_content_length
alias check_hijack_orig check_hijack
alias _call_orig _call
def _call(env)
@web_socket = env['REQUEST_PATH'] == '/cable'
_call_orig(env)
end
def check_status(status)
return if @web_socket
check_status_orig(status)
end
def check_headers(headers)
return if @web_socket
check_headers_orig(headers)
end
def check_content_type(status, headers)
return if @web_socket
check_content_type_orig(status, headers)
end
def check_content_length(status, headers)
return if @web_socket
check_content_type_orig(status, headers)
end
def check_hijack(env)
# Don't know why, but HijackWrapper break WebSocket!
return if @web_socket
check_hijack_orig(env)
end
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/436718.html
