-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
app.py
50 lines (34 loc) · 1.18 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""This is a simple cheatsheet webapp."""
import os
from flask import Flask, abort, send_from_directory
from flask_sslify import SSLify
DIR = os.path.dirname(os.path.realpath(__file__))
ROOT = os.path.join(DIR, "docs", "_build", "html")
def find_key(token):
"""Find the key from the environment variable."""
if token == os.environ.get("ACME_TOKEN"):
return os.environ.get("ACME_KEY")
for k, v in os.environ.items():
if v == token and k.startswith("ACME_TOKEN_"):
n = k.replace("ACME_TOKEN_", "")
return os.environ.get("ACME_KEY_{}".format(n))
app = Flask(__name__)
if "DYNO" in os.environ:
sslify = SSLify(app, skips=[".well-known"])
@app.route("/<path:path>")
def static_proxy(path):
"""Find static files."""
return send_from_directory(ROOT, path)
@app.route("/")
def index_redirection():
"""Redirecting index file."""
return send_from_directory(ROOT, "index.html")
@app.route("/.well-known/acme-challenge/<token>")
def acme(token):
"""Find the acme-key from environment variable."""
key = find_key(token)
if key is None:
abort(404)
return key
if __name__ == "__main__":
app.run(debug=False)