This repository has been archived on 2020-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
magic-app/magic_app/app.py

41 lines
1020 B
Python
Raw Normal View History

2020-06-30 19:03:58 +00:00
from json import loads
from pathlib import Path
from flask import Flask, render_template, send_from_directory
2020-06-30 18:28:47 +00:00
app = Flask(__name__)
2020-06-30 19:03:58 +00:00
def get_apps():
"""All apps that can be installed."""
apps_path = (Path(app.root_path) / "static" / "apps.json").absolute()
try:
with open(apps_path, "r") as handle:
return [key for key in loads(handle.read())]
except Exception as exception:
print("Failed to load apps.json, saw {}".format(str(exception)))
2020-06-30 18:28:47 +00:00
@app.route("/")
def home():
2020-06-30 19:03:58 +00:00
apps = get_apps()
return render_template("index.html", apps=apps)
2020-06-30 18:28:47 +00:00
@app.route("/apps")
2020-06-30 19:03:58 +00:00
def apps_list():
return send_from_directory("static", "apps.json")
2020-06-30 19:03:58 +00:00
@app.route("/<app>")
def app_config(app_name):
# TODO(decentral1se): clone the app repository to somewhere under /tmp read
# all the env vars, secrets, etc. and fire up a wtform and deploy button
# using a new app.html template in the templates directory
pass
2020-06-30 18:28:47 +00:00
if __name__ == "__main__":
app.run(host="0.0.0.0")