master
km0 3 years ago
parent 467dcafbb0
commit 0f823c7237

@ -7,6 +7,7 @@ app = Flask(__name__, )
sock = Sock(app)
app.wsgi_app = prefix.PrefixMiddleware(
app.wsgi_app, prefix=os.environ.get("URL_PREFIX", "")
)
@ -17,7 +18,7 @@ def index():
return render_template('index.html')
@sock.route('/echo')
@sock.route('/echo/')
def echo(sock):
while True:
data = sock.receive()

@ -18,10 +18,23 @@
).innerHTML += `<span style="color: ${color}">${text}</span><br>`;
};
console.log(location.protocol);
console.log(
location.protocol == "https:"
? "wss://"
: "ws://" +
location.host +
location.pathname.replace(new RegExp("\/" + "$"), "") +
"/echo/"
);
const socket = new WebSocket(
location.protocol == "https"
location.protocol == "https:"
? "wss://"
: "ws://" + location.host + location.pathname + "/echo/"
: "ws://" +
location.host +
location.pathname.replace(new RegExp("\/" + "$"), "") +
"/echo/"
);
socket.addEventListener("message", (ev) => {
log("<<< " + ev.data, "blue");

Loading…
Cancel
Save