From 00badeaf6395710bd75bfedd2c8ca904d05c1807 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Sun, 7 Jul 2019 12:25:01 +0200 Subject: [PATCH] Runs on different ports, uses wss if URL is https. --- client/index.ls | 8 +++++++- src/main.cr | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/index.ls b/client/index.ls index 2794895..6508365 100644 --- a/client/index.ls +++ b/client/index.ls @@ -358,7 +358,13 @@ model = { projects-list: [] } -socket = new WebSocket "ws://localhost:8888/socket" +protocol = if location.protocol == 'https' then 'wss' else 'ws' +port = if location.port then \: + location.port else '' +socket-url = protocol + '://' + location.hostname + port + "/socket" + +console.log socket-url + +socket = new WebSocket socket-url socket.onopen = (event) -> # Nothing to do here ATM. diff --git a/src/main.cr b/src/main.cr index f160f2f..4248405 100644 --- a/src/main.cr +++ b/src/main.cr @@ -30,11 +30,13 @@ get "/" do File.read "index.html" end -get "/style.css" do +get "/style.css" do |env| + env.response.content_type = "text/css" File.read "style.css" end -get "/main.js" do +get "/main.js" do |env| + env.response.content_type = "text/javascript" File.read "main.js" end