url_prefix
This commit is contained in:
parent
b9e5745331
commit
bc0e15f706
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ __pycache__/
|
|||
*.swp
|
||||
*.swo
|
||||
devices.json
|
||||
config.py
|
||||
|
|
7
config.py.template
Normal file
7
config.py.template
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Configuration settings for the Juice IOT hub server.
|
||||
`url_prefix` is the root path you wish app to reside at
|
||||
eg. https://example.com/juice.
|
||||
"""
|
||||
url_prefix = '/juice'
|
21
juice.py
21
juice.py
|
@ -2,12 +2,16 @@
|
|||
"""
|
||||
A hub for controlling IOT devices.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import copy
|
||||
import json
|
||||
|
||||
import requests
|
||||
from flask import Flask, render_template, request, abort, jsonify
|
||||
from flask import Blueprint
|
||||
|
||||
import config
|
||||
|
||||
|
||||
class RelayDevice:
|
||||
|
@ -127,11 +131,9 @@ def save_network(filepath="devices.json"):
|
|||
with open(filepath, 'w') as file:
|
||||
file.write(json.dumps(network, cls=DeviceEncoder, indent='\t'))
|
||||
|
||||
app_views = Blueprint('app_views', __name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
network = init_network()
|
||||
|
||||
@app.route('/')
|
||||
@app_views.route('/')
|
||||
def index():
|
||||
"""
|
||||
The index page.
|
||||
|
@ -139,7 +141,7 @@ def index():
|
|||
return render_template('index.html', network=network)
|
||||
|
||||
|
||||
@app.route('/toggle')
|
||||
@app_views.route('/toggle')
|
||||
def toggle():
|
||||
"""
|
||||
Toggles the state of a RelayDevice.
|
||||
|
@ -158,7 +160,7 @@ def toggle():
|
|||
save_network()
|
||||
return res
|
||||
|
||||
@app.route('/edit')
|
||||
@app_views.route('/edit')
|
||||
def edit():
|
||||
"""
|
||||
Edits the text of a particular field.
|
||||
|
@ -208,5 +210,12 @@ def make_error(code, message):
|
|||
return res
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.register_blueprint(app_views, url_prefix=config.url_prefix)
|
||||
app.secret_key = os.urandom(32)
|
||||
app.config['APPLICATION_ROOT'] = config.url_prefix
|
||||
network = init_network()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5300)
|
||||
|
|
Loading…
Reference in New Issue
Block a user