summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--megapixels/app/server/create.py30
2 files changed, 13 insertions, 21 deletions
diff --git a/README.md b/README.md
index 27dd1b38..e8c5731b 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,9 @@ python cli_site.py watch
npm run watch
```
-In addition, run the server, which will serve some HTML (you may need to add index.html to URLs... alas):
+## Running the various servers
+
+Run the web server, which will serve some HTML (you will need to add index.html to URLs... alas!):
```
python cli_flask.py run
diff --git a/megapixels/app/server/create.py b/megapixels/app/server/create.py
index a1ce56df..b6ca7ba3 100644
--- a/megapixels/app/server/create.py
+++ b/megapixels/app/server/create.py
@@ -1,3 +1,4 @@
+import os
import logging
import logging.handlers
@@ -13,7 +14,7 @@ logging.getLogger().addHandler(logging.StreamHandler())
logging.debug("starting app")
-from flask import Flask, Blueprint, jsonify, send_from_directory
+from flask import Flask, Blueprint, jsonify, send_from_directory, request
from flask_sqlalchemy import SQLAlchemy
from app.models.sql_factory import connection_url, load_sql_datasets
@@ -38,7 +39,14 @@ def create_app(script_info=None):
app.register_blueprint(api, url_prefix='/api')
app.register_blueprint(api_task, url_prefix='/task')
- app.add_url_rule('/<path:file_relative_path_to_root>', 'serve_page', serve_page, methods=['GET'])
+
+ @app.errorhandler(404)
+ def page_not_found(e):
+ path = os.path.join(os.path.dirname(__file__), './static', request.path[1:], 'index.html')
+ if os.path.exists(path):
+ with open(path, "r") as f:
+ return f.read(), 200
+ return "404!!!!!!!!!!!!1", 404
@app.route('/', methods=['GET'])
def index():
@@ -48,22 +56,4 @@ def create_app(script_info=None):
def shell_context():
return { 'app': app, 'db': db }
- @app.route("/site-map")
- def site_map():
- links = []
- for rule in app.url_map.iter_rules():
- # url = url_for(rule.endpoint, **(rule.defaults or {}))
- # print(url)
- links.append((rule.endpoint))
- return(jsonify(links))
-
return app
-
-def serve_page(file_relative_path_to_root):
- """
- trying to get this to serve /path/ with /path/index.html,
- ...but it doesnt actually matter for production...
- """
- if file_relative_path_to_root[-1] == '/':
- file_relative_path_to_root += 'index.html'
- return send_from_directory("static", file_relative_path_to_root)