-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
42 lines (34 loc) · 1.08 KB
/
api.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
from eve import Eve
from eve_mongoengine import EveMongoengine
from eve.auth import BasicAuth
# init application
from public.models import *
from user.models import User
MONGODB_SETTINGS = {
# 'MONGO_HOST': 'localhost',
# 'MONGO_PORT': 27017,
# 'MONGO_USERNAME' : None,
# 'MONGO_PASSWORD': None,
'MONGO_DBNAME': 'houzee',
'X_DOMAINS': '*',
'ALLOW_OVERRIDE_HTTP_METHOD': 'true',
'query_objectid_as_string': 'True',
'JSON_SORT_KEYS': 'true',
'DOMAIN': {'resident': {}},
'PAGINATION_LIMIT': 200,
'max_results': 80
}
class MyBasicAuth(BasicAuth):
def check_auth(self, username, password, allowed_roles, resource,
method):
return username == 'admin' and password == 'secret'
app = Eve(settings=MONGODB_SETTINGS, auth=MyBasicAuth)
# init extension
ext = EveMongoengine(app)
# register model to eve
ext.add_model(Resident)
ext.add_model(Township)
ext.add_model(Item, query_objectid_as_string='true')
ext.add_model(Message, query_objectid_as_string='true')
# let's roll
app.run(host='127.0.0.1', port=8001, debug=True)