Skip to content

Commit 7c446d4

Browse files
authored
Merge pull request #29 from amorygalili/allow-networktables-to-serve-from-different-host
Allow networktables to serve from different host
2 parents 37756dc + c364607 commit 7c446d4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pynetworktables2js/js/networktables.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,17 @@ var NetworkTables = new function () {
294294
host = "ws:";
295295
}
296296

297-
host += "//" + loc.host;
297+
// If the websocket is being served from a different host allow users
298+
// to add a data-nt-host="" attribute to the script tag loading
299+
// Networktables.
300+
var ntHostElement = document.querySelector('[data-nt-host]');
301+
if (ntHostElement) {
302+
var ntHost = ntHostElement.getAttribute('data-nt-host');
303+
host += "//" + ntHost;
304+
} else {
305+
host += "//" + loc.host;
306+
}
307+
298308
host += "/networktables/ws";
299309

300310
function createSocket() {

pynetworktables2js/tornado_handlers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def open(self):
2626
self.ioloop = IOLoop.current()
2727
self.ntserial = NTSerial(self.send_msg_threadsafe)
2828

29+
def check_origin(self, origin):
30+
"""
31+
Allow CORS requests
32+
"""
33+
return True
34+
2935
def on_message(self, message):
3036
if self.ntserial is not None:
3137
self.ntserial.process_update(message)

0 commit comments

Comments
 (0)