-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
28 lines (23 loc) · 1 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
try:
from flask import Flask
from flask import send_from_directory
except ImportError:
print("You don't have Flask installed, run `$ pip3 install flask` and try again")
exit(1)
import os
static_file_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), './')
app = Flask(__name__)
# Serving the index file
@app.route('/', methods=['GET'])
def serve_dir_directory_index():
if os.path.exists("index.html"):
return send_from_directory(static_file_dir, 'index.html')
else:
return "<h1 align='center'>404</h1><h2 align='center'>Missing index.html file</h2><p align='center'><img src='https://ucarecdn.com/3a0e7d8b-25f3-4e2f-add2-016064b04075/rigobaby.jpg' /></p>"
# Serving any other image
@app.route('/<path:path>', methods=['GET'])
def serve_any_other_file(path):
if not os.path.isfile(os.path.join(static_file_dir, path)):
path = os.path.join(path, 'index.html')
return send_from_directory(static_file_dir, path)
app.run(host='0.0.0.0',port=3000, debug=True)