add websocket router and html/js test client

This commit is contained in:
2023-01-28 16:40:46 +01:00
parent 7729f97291
commit 53e694be9a
3 changed files with 46 additions and 2 deletions

9
app.py
View File

@@ -1,10 +1,12 @@
from flask import Flask, render_template, url_for, request, redirect, Response, abort, session
from flask_sock import Sock
from flask_sqlalchemy import SQLAlchemy
from werkzeug.middleware.proxy_fix import ProxyFix
from datetime import datetime
import magic
import random
import string
import json
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
@@ -12,6 +14,7 @@ app.secret_key = '029c0gji3jfo3o8h938vhwtfmh3t39th'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///cloudvars.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
sock = Sock(app)
class variables(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
@@ -25,6 +28,12 @@ def get_date():
date = datetime.now()
return { "now": date.strftime("%Y-%m-%d") }
@sock.route('/<namespace>')
def echo(sock,namespace):
while True:
data = json.loads(sock.receive())
sock.send(json.dumps({"method":"set","name":"test","value":"abcd"}))
@app.route('/', methods = ['GET'])
def index():
return render_template('index.html')