/
app.py
54 lines (45 loc) · 1.42 KB
/
app.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import json
import redis
from flask import (
Flask, flash, render_template,
redirect, request, session,
url_for, abort, Blueprint, Response,)
from flask_pymongo import PyMongo
from bson.objectid import ObjectId
from error_handlers import error_handlers
from movies import movies
from auth import auth
from database import mongo
from flask_session import Session
if os.path.exists("env.py"):
import env
app = Flask(__name__)
# Blueprint for error handling
app.register_blueprint(error_handlers, url_prefix="/error/")
# Blueprint for movie routes
app.register_blueprint(movies)
# Blueprint for authentication routes
app.register_blueprint(auth)
# Get database access from env.py
app.config["MONGO_DBNAME"] = os.environ.get("MONGO_DBNAME")
app.config["MONGO_URI"] = os.environ.get("MONGO_URI")
# Set session type to filesystem
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_PERMANENT'] = False
app.config['SESSION_USE_SIGNER'] = True
app.config['SESSION_REDIS'] = redis.from_url(
os.environ.get("REDIS_URL"), health_check_interval=30)
# Get secret key from env.py
app.secret_key = os.environ.get("SECRET_KEY")
# Initiate PyMongo
mongo.init_app(app)
# Initiate Flask Session (server-side)
sess = Session(app)
@app.route("/")
def home():
return render_template("home.html")
if __name__ == "__main__":
app.run(host=os.environ.get("IP"),
port=int(os.environ.get("PORT")),
debug=True)