1
0
Fork 0
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:
Kasper Timm Hansen 2019-03-11 13:54:28 +01:00 committed by GitHub
commit 33800d2330
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -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
}
}

View file

@ -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)
})
})
})