add websocket router and html/js test client
This commit is contained in:
9
app.py
9
app.py
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user