Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the webapp from the server #854

Merged
merged 3 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 10 additions & 47 deletions 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 All @@ -87,52 +91,6 @@
def index():
return static_file("index.html", static_path)

# Bunch of static pages that constitute our website
# Should we have gone for something like django instead after all?
# If this gets to be too much, we should definitely consider that
@route("/docs/<filename>")
def docs(filename):
if filename != "privacy.html" and filename != "support.html" and filename != "about.html" and filename != "consent.html" and filename != "approval_letter.pdf":
logging.error("Request for unknown filename "% filename)
logging.error("Request for unknown filename "% filename)
return HTTPError(404, "Don't try to hack me, you evil spammer")
else:
return static_file(filename, "%s/%s" % (static_path, "docs"))

@route("/<filename>")
def docs(filename):
if filename != "privacy" and filename != "support" and filename != "about" and filename != "consent":
return HTTPError(404, "Don't try to hack me, you evil spammer")
else:
return static_file("%s.html" % filename, "%s/%s" % (static_path, "docs"))

# Serve up the components of the webapp - library files, our javascript and css
# files, and HTML templates, properly
@route('/css/<filepath:path>')
def server_css(filepath):
logging.debug("static filepath = %s" % filepath)
return static_file(filepath, "%s/%s" % (static_path, "css"))

@route('/img/<filepath:path>')
def server_img(filepath):
logging.debug("static filepath = %s" % filepath)
return static_file(filepath, "%s/%s" % (static_path, "img"))

@route('/js/<filepath:path>')
def server_js(filepath):
logging.debug("static filepath = %s" % filepath)
return static_file(filepath, "%s/%s" % (static_path, "js"))

@route('/lib/<filepath:path>')
def server_lib(filepath):
logging.debug("static filepath = %s" % filepath)
return static_file(filepath, "%s/%s" % (static_path, "lib"))

@route('/templates/<filepath:path>')
def server_templates(filepath):
logging.debug("static filepath = %s" % filepath)
return static_file(filepath, "%s/%s" % (static_path, "templates"))

# Backward compat to handle older clients
# Remove in 2023 after everybody has upgraded
# We used to use the presence or absence of the "user" field
Expand Down Expand Up @@ -441,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
3 changes: 0 additions & 3 deletions webapp/.bowerrc

This file was deleted.

14 changes: 0 additions & 14 deletions webapp/.editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions webapp/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions webapp/bower.json

This file was deleted.

42 changes: 0 additions & 42 deletions webapp/config.xml

This file was deleted.

51 changes: 0 additions & 51 deletions webapp/gulpfile.js

This file was deleted.

83 changes: 0 additions & 83 deletions webapp/hooks/README.md

This file was deleted.

Loading