Skip to content

Commit

Permalink
Set up a custom 404 redirect to the OpenPATH page
Browse files Browse the repository at this point in the history
Instead of a weird 404 page.
Since this is approved by NREL comms, we don't need any other 404 or index page for now
  • Loading branch information
shankari committed Jun 5, 2022
1 parent 51cb5ef commit 964ed28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion conf/net/api/webserver.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"static_path" : "webapp/www/",
"python_path" : "main",
"log_base_dir" : ".",
"log_file" : "debug.log"
"log_file" : "debug.log",
"404_redirect": "https://www.nrel.gov/transportation/openpath.html"
},
"__comment" : "Fill this in for the production server. port will almost certainly be 80 or 443. For iOS, using localhost allows you to test without an internet connection. For AWS and android, make sure that the host 0.0.0.0, localhost does not seem to work",
"server" : {
Expand Down
11 changes: 10 additions & 1 deletion emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from past.utils import old_div
import json
from random import randrange
from emission.net.api.bottle import route, post, get, run, template, static_file, request, app, HTTPError, abort, BaseRequest, JSONPlugin, response
from emission.net.api.bottle import route, post, get, run, template, static_file, request, app, HTTPError, abort, BaseRequest, JSONPlugin, response, error, redirect
import emission.net.api.bottle as bt
# To support dynamic loading of client-specific libraries
import sys
Expand Down Expand Up @@ -58,6 +58,8 @@
logging.debug("webserver not configured, falling back to sample, default configuration")
config_file = open('conf/net/api/webserver.conf.sample')

OPENPATH_URL="https://www.nrel.gov/transportation/openpath.html"

config_data = json.load(config_file)
config_file.close()
static_path = config_data["paths"]["static_path"]
Expand All @@ -68,6 +70,8 @@
log_base_dir = config_data["paths"]["log_base_dir"]
auth_method = config_data["server"]["auth"]
aggregate_call_auth = config_data["server"]["aggregate_call_auth"]
# not_found_redirect = "foo" if len(config_data["paths"]) == 5 else "bar"
not_found_redirect = config_data["paths"]["404_redirect"] if "404_redirect" in config_data["paths"] else OPENPATH_URL

BaseRequest.MEMFILE_MAX = 1024 * 1024 * 1024 # Allow the request size to be 1G
# to accomodate large section sizes
Expand Down Expand Up @@ -395,6 +399,11 @@ def habiticaProxy():
method_args)
# Data source integration END

@error(404)
def error404(error):
response.status = 301
response.set_header('Location', "https://www.nrel.gov/transportation/openpath.html")

@app.hook('before_request')
def before_request():
print("START %s %s %s" % (datetime.now(), request.method, request.path))
Expand Down

0 comments on commit 964ed28

Please sign in to comment.