-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·42 lines (36 loc) · 1.22 KB
/
server.py
File metadata and controls
executable file
·42 lines (36 loc) · 1.22 KB
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
#!/usr/bin/python
from bottle import run, debug, route, template, request, abort, hook, response
from datetime import timedelta, datetime
import json, time
import pymongo
#################################
# GLOBALS
#################################
import hdl_pybus
#################################
# Load up MongoDB
#################################
connection = pymongo.Connection('localhost', 27017)
#################################
# Enable Cross access
#################################
@hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Credentials'] = True
response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
#################################
# Handlers for PyBus
#################################
@route('/api/pybus/add', method="POST")
def pyb_add():
return hdl_pybus.add(connection)
# - get_all - Gets all posts within a number of days
@route('/api/pybus/get_all')
@route('/api/pybus/get_all/:numDays')
def pyb_get_all(numDays=7):
return hdl_pybus.get_all(connection, numDays)
#################################
# MAIN
#################################
run(host='0.0.0.0', debug=True, port=7725, reloader=True)