-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
45 lines (32 loc) · 1.16 KB
/
index.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
from flask import Flask, render_template
from flask_restful import Resource, Api
from server.resources.search import Search
from server.resources.user import UserRegister
from flask_jwt import JWT
from server.security import authenticate, identity
app = Flask(__name__,static_folder="./static", template_folder="./templates")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = 'phidb'
api = Api(app)
@app.before_first_request
def create_tables():
db.create_all()
jwt = JWT(app, authenticate, identity) # /auth
@app.route('/')
def root():
return render_template('index.html')
# stop browser from caching static bundle.js file // this is for dev env only.
@app.after_request
def add_header(r):
r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"
r.headers['Cache-Control'] = 'public, max-age=0'
return r
api.add_resource(UserRegister, '/register')
api.add_resource(Search, '/search')
if __name__ == '__main__':
from server.db import db
db.init_app(app)
app.run(port=5000, debug=True)