mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #35525 from audiolion/feature/dynamic-actioncable-websocket-url
feat(js): Dynamic Actioncable WebSocket URL
This commit is contained in:
commit
33800d2330
2 changed files with 13 additions and 3 deletions
|
@ -30,14 +30,16 @@ export function getConfig(name) {
|
|||
}
|
||||
|
||||
export function createWebSocketURL(url) {
|
||||
if (url && !/^wss?:/i.test(url)) {
|
||||
const webSocketURL = typeof url === 'function' ? url() : url;
|
||||
|
||||
if (webSocketURL && !/^wss?:/i.test(webSocketURL)) {
|
||||
const a = document.createElement("a")
|
||||
a.href = url
|
||||
a.href = webSocketURL
|
||||
// Fix populating Location properties in IE. Otherwise, protocol will be blank.
|
||||
a.href = a.href
|
||||
a.protocol = a.protocol.replace("http", "ws")
|
||||
return a.href
|
||||
} else {
|
||||
return url
|
||||
return webSocketURL
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,13 @@ module("ActionCable", () => {
|
|||
|
||||
assert.equal(consumer.url, testURL)
|
||||
})
|
||||
|
||||
test("uses function to generate URL", assert => {
|
||||
const generateURL = () => {
|
||||
return testURL
|
||||
}
|
||||
const consumer = ActionCable.createConsumer(generateURL)
|
||||
assert.equal(consumer.url, testURL)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue