master
km0 2 years ago
parent 467dcafbb0
commit 0f823c7237

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

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

Loading…
Cancel
Save