url_prefix
This commit is contained in:
parent
b9e5745331
commit
bc0e15f706
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ __pycache__/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
devices.json
|
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.
|
A hub for controlling IOT devices.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, render_template, request, abort, jsonify
|
from flask import Flask, render_template, request, abort, jsonify
|
||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
class RelayDevice:
|
class RelayDevice:
|
||||||
|
@ -127,11 +131,9 @@ def save_network(filepath="devices.json"):
|
||||||
with open(filepath, 'w') as file:
|
with open(filepath, 'w') as file:
|
||||||
file.write(json.dumps(network, cls=DeviceEncoder, indent='\t'))
|
file.write(json.dumps(network, cls=DeviceEncoder, indent='\t'))
|
||||||
|
|
||||||
|
app_views = Blueprint('app_views', __name__)
|
||||||
|
|
||||||
app = Flask(__name__)
|
@app_views.route('/')
|
||||||
network = init_network()
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
def index():
|
||||||
"""
|
"""
|
||||||
The index page.
|
The index page.
|
||||||
|
@ -139,7 +141,7 @@ def index():
|
||||||
return render_template('index.html', network=network)
|
return render_template('index.html', network=network)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/toggle')
|
@app_views.route('/toggle')
|
||||||
def toggle():
|
def toggle():
|
||||||
"""
|
"""
|
||||||
Toggles the state of a RelayDevice.
|
Toggles the state of a RelayDevice.
|
||||||
|
@ -158,7 +160,7 @@ def toggle():
|
||||||
save_network()
|
save_network()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@app.route('/edit')
|
@app_views.route('/edit')
|
||||||
def edit():
|
def edit():
|
||||||
"""
|
"""
|
||||||
Edits the text of a particular field.
|
Edits the text of a particular field.
|
||||||
|
@ -208,5 +210,12 @@ def make_error(code, message):
|
||||||
return res
|
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__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5300)
|
app.run(host='0.0.0.0', port=5300)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user