forked from miguelgrinberg/flasky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 17: Heroku support with Waitress (17c-waitress)
- Loading branch information
1 parent
5af7fc5
commit f662f63
Showing
5 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: waitress-serve --port=$PORT flasky:app |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ class Config: | |
FLASKY_MAIL_SUBJECT_PREFIX = '[Flasky]' | ||
FLASKY_MAIL_SENDER = 'Flasky Admin <[email protected]>' | ||
FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN') | ||
SSL_REDIRECT = False | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
SQLALCHEMY_RECORD_QUERIES = True | ||
FLASKY_POSTS_PER_PAGE = 20 | ||
|
@@ -66,10 +67,33 @@ def init_app(cls, app): | |
app.logger.addHandler(mail_handler) | ||
|
||
|
||
class HerokuConfig(ProductionConfig): | ||
SSL_REDIRECT = True if os.environ.get('DYNO') else False | ||
|
||
@classmethod | ||
def init_app(cls, app): | ||
ProductionConfig.init_app(app) | ||
|
||
# handle reverse proxy server headers | ||
try: | ||
from werkzeug.middleware.proxy_fix import ProxyFix | ||
except ImportError: | ||
from werkzeug.contrib.fixers import ProxyFix | ||
app.wsgi_app = ProxyFix(app.wsgi_app) | ||
|
||
# log to stderr | ||
import logging | ||
from logging import StreamHandler | ||
file_handler = StreamHandler() | ||
file_handler.setLevel(logging.INFO) | ||
app.logger.addHandler(file_handler) | ||
|
||
|
||
config = { | ||
'development': DevelopmentConfig, | ||
'testing': TestingConfig, | ||
'production': ProductionConfig, | ||
'heroku': HerokuConfig, | ||
|
||
'default': DevelopmentConfig | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# this requirements file is used by Heroku | ||
# requirements for other configurations are located in the requirements subdirectory | ||
-r requirements/heroku.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-r prod.txt | ||
Flask-SSLify==0.1.5 | ||
waitress==1.0.2 | ||
psycopg2==2.7.3 |