Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Improvements to run more smoothly on Google AppEngine.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matir committed Jan 20, 2016
1 parent 288b700 commit 3717ae5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ attachments
attachments/**
static/js/app.min.js
.virtualenv
lib
30 changes: 30 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
application: yourappnamehere
version: release-1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /css
static_dir: /static/css
secure: always

- url: /js
static_dir: /static/js
secure: always

- url: /partials
static_dir: /static/partials
secure: always

- url: /fonts
static_dir: /static/fonts
secure: always

- url: /third_party
static_dir: /static/third_party
secure: always

- url: /.*
script: main.app
secure: always
3 changes: 3 additions & 0 deletions appengine_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from google.appengine.ext import vendor

vendor.add('lib')
Empty file added lib/.keep
Empty file.
44 changes: 27 additions & 17 deletions scoreboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import flask
import logging
import os
import re
from werkzeug import exceptions
from werkzeug.utils import ImportStringError


app = flask.Flask(
Expand All @@ -31,23 +29,35 @@
app.config.setdefault('CWD', os.path.dirname(os.path.realpath(__file__)))
app.config.setdefault('ERROR_404_HELP', False)

# Main logger
if not app.debug:

def on_appengine():
"""Returns true if we're running on AppEngine."""
runtime = os.environ.get('SERVER_SOFTWARE', '')
return (runtime.startswith('Development/') or
runtime.startswith('Google App Engine/'))


# log to files unless on AppEngine
if not on_appengine():
# Main logger
if not app.debug:
handler = logging.FileHandler(
app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(message)s'))
app.logger.addHandler(handler)

# Challenge logger
handler = logging.FileHandler(
app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(message)s'))
app.logger.addHandler(handler)

# Challenge logger
handler = logging.FileHandler(
app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
logger = logging.getLogger('scoreboard')
logger.addHandler(handler)
app.challenge_log = logger
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
logger = logging.getLogger('scoreboard')
logger.addHandler(handler)
app.challenge_log = logger
else:
app.challenge_log = app.logger


# Install a default error handler
Expand Down

0 comments on commit 3717ae5

Please sign in to comment.