forked from OSDC-Code-Maven/open-source-by-organizations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·35 lines (30 loc) · 932 Bytes
/
app.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
29
30
31
32
33
34
35
#!/usr/bin/env python
import os
from flask import Flask, send_file
"""
flask run
DIR=files/good_output/good/ flask run
"""
app = Flask(__name__)
#root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '_site')
root = os.path.join(os.getcwd(), '_site')
root = os.environ.get('DIR', root)
@app.route("/")
def main():
return send_file(os.path.join(root, 'index.html'))
@app.route("/<path:fullpath>")
def all(fullpath):
extensions = ['.js', '.css', '.json', '.ico']
for ext in extensions:
if fullpath.endswith(ext):
path = os.path.join(root, fullpath)
if os.path.exists(path):
return send_file(path)
else:
#print(f"No file {path}")
return '', 404
if fullpath.endswith('/'):
fullpath += 'index'
return send_file(os.path.join(root, f"{fullpath}.html"))
if __name__ == "__main__":
app.run(debug=True)