49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
A simple Flask application for interacting with WHSPAH shockers.
|
|
"""
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
|
|
import waitress.server
|
|
import flask
|
|
|
|
app = flask.Flask(__name__, static_folder='./www/')
|
|
|
|
@app.route('/', defaults={'path': 'index.html'})
|
|
@app.route('/<path:path>')
|
|
def staticPage(path):
|
|
"""
|
|
Returns anything requested in the static folder.
|
|
"""
|
|
|
|
if os.path.isfile(os.path.join(app.static_folder, path, 'index.html')):
|
|
path = os.path.join(path, 'index.html')
|
|
|
|
return flask.send_from_directory(app.static_folder, path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('-d', '--debug', action='store_true')
|
|
parser.add_argument('--ip', type=str, default='0.0.0.0')
|
|
parser.add_argument('--port', type=int, default=8000)
|
|
args = parser.parse_args()
|
|
|
|
if args.debug:
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
else:
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
if args.debug:
|
|
app.run(host=args.ip, port=args.port, debug=True)
|
|
else:
|
|
server = waitress.server.create_server(app, host=args.ip, port=args.port)
|
|
print(f'Serving at http://{args.ip}:{args.port}/')
|
|
try:
|
|
server.run()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
server.close()
|