Skip to content

Commit

Permalink
#10 MongoDB connection successfully established and routes made more …
Browse files Browse the repository at this point in the history
…legible
  • Loading branch information
gkeswani92 committed Mar 11, 2017
1 parent 79d583a commit e53e3b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
3 changes: 3 additions & 0 deletions api_cmds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
login_page = Blueprint('login', __name__, template_folder='templates')
sign_out_page = Blueprint('sign_out', __name__, template_folder='templates')

# All routes must be added here to be available in the application
routes = [index_page, about_page, sign_up_page, home_page, login_page, sign_out_page]


@index_page.route('/')
def index():
Expand Down
17 changes: 9 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
version: '2'

services:
postgres:
image: postgres:latest
container_name: postgres_livereviews
ports:
- "5432:5432"

mongodb:
image: mongo:latest
container_name: mongodb_livereviews
ports:
- "27017:27017"

flask:
restart: always
build: .
container_name: flask_livereviews
ports:
- 8000:8000
command: bash -c "sleep 2; python run.py"
- "8000:8000"
command: python run.py
volumes:
- .:/code
links:
- postgres:postgres_livereviews
- mongodb:mongodb_livereviews

networks:
esnet:
driver: bridge
- postgres
- mongodb
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ decorator==4.0.10
Flask==0.11.1
Flask-SQLAlchemy==2.1
Flask-WTF==0.13.1
pymongo==3.4.0
geocode==0.1.0
geocoder==1.17.4
gunicorn==19.6.0
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
mongoengine==0.11.0
packaging==16.8
psycopg2==2.6.2
py==1.4.32
Expand Down
32 changes: 14 additions & 18 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
from models.database_setup import SQLAlchemyService

from flask import Flask
from api_cmds.routes import about_page
from api_cmds.routes import index_page
from api_cmds.routes import sign_up_page
from api_cmds.routes import sign_out_page
from api_cmds.routes import home_page
from api_cmds.routes import login_page
import pymongo

from api_cmds.routes import routes

app = Flask(__name__)
app.secret_key = 'development-key'

# Setup database connectivity
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/location_based_service'
# Setup connectivity with MongoDB
mongo_client = pymongo.MongoClient('mongodb', 27017)

# Setup database connectivity with Postgres
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres/location_based_service'
SQLAlchemyService().instantiate_sql_alchemy()
SQLAlchemyService().initialize_db(app)

# Register blueprint for index and about pages
app.register_blueprint(index_page)
app.register_blueprint(about_page)
app.register_blueprint(sign_up_page)
app.register_blueprint(sign_out_page)
app.register_blueprint(home_page)
app.register_blueprint(login_page)

app.secret_key = 'development-key'
# Register all the url routes
for route in routes:
app.register_blueprint(route)

if __name__ == "__main__":
# Run flask app in debug bug on localhost
app.run(host="0.0.0.0", port=8000, debug=True)
app.run(host="0.0.0.0", port=8000, debug=True)

0 comments on commit e53e3b9

Please sign in to comment.