diff --git a/src/config.js b/src/config.js index 8239b7fb..9f53b0f6 100644 --- a/src/config.js +++ b/src/config.js @@ -317,10 +317,17 @@ function preprocessConfig(cfg) { cfg.io["ipv6-default"] = cfg.io["ipv6-ssl"] || cfg.io["ipv6-nossl"]; // sioconfig - var sioconfig = "var IO_URLS={'ipv4-nossl':'" + cfg.io["ipv4-nossl"] + "'," + - "'ipv4-ssl':'" + cfg.io["ipv4-ssl"] + "'," + - "'ipv6-nossl':'" + cfg.io["ipv6-nossl"] + "'," + - "'ipv6-ssl':'" + cfg.io["ipv6-ssl"] + "'};"; + // TODO this whole thing is messy, need to redo how the socket address is sent + var sioconfigjson = { + "ipv4-nossl": cfg.io["ipv4-nossl"], + "ipv4-ssl": cfg.io["ipv4-ssl"], + "ipv6-nossl": cfg.io["ipv6-nossl"], + "ipv6-ssl": cfg.io["ipv6-ssl"] + }; + + var sioconfig = JSON.stringify(sioconfigjson); + sioconfig = "var IO_URLS=" + sioconfig + ";"; + cfg.sioconfigjson = sioconfigjson; cfg.sioconfig = sioconfig; // Generate RegExps for reserved names diff --git a/src/web/webserver.js b/src/web/webserver.js index 20ae8847..3bd43647 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -120,6 +120,11 @@ function handleIndex(req, res) { * Handles a request for the socket.io information */ function handleSocketConfig(req, res) { + if (/\.json$/.test(req.path)) { + res.json(Config.get("sioconfigjson")); + return; + } + res.type("application/javascript"); var sioconfig = Config.get("sioconfig"); @@ -237,7 +242,7 @@ module.exports = { app.get("/r/:channel", handleChannel); app.get("/", handleIndex); - app.get("/sioconfig", handleSocketConfig); + app.get("/sioconfig(.json)?", handleSocketConfig); app.get("/useragreement", handleUserAgreement); app.get("/contact", handleContactPage); require("./auth").init(app);