[英]Websockets on Spring boot website hosted on Azure returns Error 503/403
[英]Clojurescript Websockets with Sente 403 Error
我正在嘗試從本地主機上的兩個不同端口設置 Web 套接字連接。 我正在使用 Sente 和 Immutant。 我有以下內容,但在嘗試連接時返回 403 forbidden
服務器文件
(defn handler
"Comment"
[]
"<h1>Hello World</h1>")
(let [{:keys [ch-recv send-fn connected-uids
ajax-post-fn ajax-get-or-ws-handshake-fn]}
(sente/make-channel-socket! (get-sch-adapter) {})]
(def ring-ajax-post ajax-post-fn)
(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def connected-uids connected-uids) ; Watchable, read-only atom
)
(defroutes app
"The router."
(GET "/" [] (handler))
(GET "/chsk" req (ring-ajax-get-or-ws-handshake req))
(POST "/chsk" req (ring-ajax-post req))
(route/not-found
"<h1>Page not found</h1>"))
(def my-app
(-> app
;; Add necessary Ring middleware:
ring.middleware.keyword-params/wrap-keyword-params
ring.middleware.params/wrap-params))
(def wrapped
(wrap-cors my-app :access-control-allow-origin [#".*"]
:access-control-allow-methods [:get :put :post :delete]))
(defn -main
"Start the server"
[& args]
(immutant/run wrapped {:host "localhost" :port 8080 :path "/"}))
這不會引發任何錯誤,並且“/”路由正確顯示。
客戶端.cljs
(let [{:keys [chsk ch-recv send-fn state]}
(sente/make-channel-socket! "/chsk" ; Note the same path as before
"sdasds" ; dummy
{:type :auto ; e/o #{:auto :ajax :ws}
:host "localhost:8080/"
}
)]
(def chsk chsk)
(def ch-chsk ch-recv) ; ChannelSocket's receive channel
(def chsk-send! send-fn) ; ChannelSocket's send API fn
(def chsk-state state) ; Watchable, read-only atom
)
這會在嘗試連接時引發 403 錯誤。 我不確定它為什么會這樣做,我已經研究了一段時間,但結果很差。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.