-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunapp.py
More file actions
25 lines (20 loc) · 788 Bytes
/
runapp.py
File metadata and controls
25 lines (20 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import configparser
import os
from paste.deploy import loadapp
from waitress import serve
# TODO: Automate initializedb.py to run after deployment
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
# This part is Heroku specific!
db_url = os.environ['DATABASE_URL']
# If enviroment contains DATABASE_URL, add it to the production configuration
# file.
if db_url != None:
parser = configparser.SafeConfigParser()
parser.read('production.ini')
parser.set('app:main', 'sqlalchemy.url', db_url)
with open('production.ini', 'w') as configfile:
parser.write(configfile)
# Heroku specific part ends
app = loadapp('config:production.ini', relative_to='.')
serve(app, host='0.0.0.0', port=port)