-
-
Save famanson/9bdf46627d7c803c0457 to your computer and use it in GitHub Desktop.
Main application file for Flask-based Ember frontend endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-coding: utf-8-*- | |
''' | |
Main application file for Flask-based Ember frontend endpoint | |
''' | |
import logging | |
import sys | |
from flask import Flask, request, redirect | |
from redis_pool import get_redis | |
# Gunicorn, by default, will search for the 'application' name, so use it | |
# for convenience | |
application = Flask('test') | |
# Set up logging on the application | |
application.logger.addHandler(logging.StreamHandler(sys.stderr)) | |
application.logger.setLevel('INFO') | |
redis = get_redis() | |
@application.route('/', methods=['GET']) | |
def index(): | |
""" | |
This application: | |
- First get the latest frontend deployed revision from Redis | |
- Then return the index.html file stored in Redis under that exact key | |
""" | |
current_key = redis.get('app-name:current') # This is the reference to the revision deployed | |
# Here comes the HTML | |
return redis.get(current_key) | |
@application.errorhandler(404) | |
def page_not_found(e): | |
""" | |
Because Ember uses the hash location to determine the route, we redirect | |
URLs without the hash prefix in the base URL that results in 404 error to | |
the equivalent with the hash. | |
You need to add your own redirection logic here (adding a 'transition' query | |
parameter to the index route and redirect it subsequently to the correct | |
Ember route is one way to do it | |
""" | |
if request.path.startswith('/'): | |
# Do some work here depending on your own EmberJS code setup to redirect to the right | |
# end point | |
return 'MAGIC' | |
if __name__ == '__main__': | |
application.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment