-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
40 lines (32 loc) · 1.01 KB
/
application.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
from flask import render_template, jsonify, request, Flask
from flask_cors import CORS
from whitenoise import WhiteNoise
from dateutil import parser
import requests
from pymongo import MongoClient
from settings import PRODUCTION, APP_SECRET
application = Flask(__name__)
application.debug = True
application.config['SECRET_KEY'] = APP_SECRET
cors = CORS(application)
static = WhiteNoise(application, root='../static/')
@application.route('/getPosts', methods=['GET'])
def get_posts():
client = MongoClient('localhost', 27017)
db = client.test_database
db_posts = db.posts.find()
posts = []
for post in db_posts:
del post['_id']
posts.append(post)
response = jsonify({'posts': posts})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@application.route('/', methods=['GET'])
def app():
return render_template('index.html');
if __name__ == "__main__":
application.debug = True
if PRODUCTION:
application.debug = False
application.run()