|
| 1 | +import os |
| 2 | +import logging |
| 3 | +import re |
| 4 | + |
| 5 | +import flask_restx as frx |
| 6 | +from flask import Flask |
| 7 | +from flask_cors import CORS |
| 8 | + |
| 9 | +from dat_backend.reverse_proxy import ReverseProxied |
| 10 | + |
| 11 | +__version__ = "0.4.0" |
| 12 | + |
| 13 | +app = Flask(__name__) |
| 14 | +# Enable CORS, allowing all nsidc.org domains. |
| 15 | +CORS( |
| 16 | + app, |
| 17 | + origins=[re.compile(r"^https?:\/\/(.*\.)?nsidc\.org")], |
| 18 | + expose_headers=["content-disposition"], |
| 19 | + supports_credentials=True, |
| 20 | +) |
| 21 | +api = frx.Api( |
| 22 | + app, |
| 23 | + version=__version__, |
| 24 | + title="Data Access Tool API", |
| 25 | + description="Backend services for the Data Access Tool.", |
| 26 | +) |
| 27 | + |
| 28 | +app.wsgi_app = ReverseProxied(app.wsgi_app) # type: ignore[method-assign] |
| 29 | + |
| 30 | +app.logger.setLevel(logging.INFO) |
| 31 | + |
| 32 | +secret_key = os.environ.get("DAT_FLASK_SECRET_KEY") |
| 33 | +app.secret_key = secret_key |
| 34 | + |
| 35 | + |
| 36 | +# Imports of modules containing routes come after . This is necessary so that all of the |
| 37 | +# APIs are defined when this file is done initializing. |
| 38 | +from dat_backend.routes.earthdata_download import auth, get_links # noqa |
| 39 | +from dat_backend.routes import status, python_script # noqa |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + # `ssl_context` option: |
| 43 | + # https://werkzeug.palletsprojects.com/en/2.3.x/serving/#werkzeug.serving.run_simple |
| 44 | + app.run(host="0.0.0.0", debug=True, ssl_context="adhoc") |
0 commit comments