-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
45 lines (34 loc) · 1.27 KB
/
wsgi.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
import os
import falcon
from wsgiref import simple_server
from analyzer import settings
from analyzer.services import Analyzer
from analyzer.exceptions import AnalyzerError
from analyzer.resources import FeatureResource
from analyzer.resources import FeatureDetailResource
from analyzer.resources import TrainResource
from analyzer.resources import BuildResource
from analyzer.resources import ClassifyResource
from analyzer.middlewares import AuthMiddleware
from analyzer.middlewares import RequireJSON
from analyzer.middlewares import JSONTranslator
# initializing the analyzer
analyzer = Analyzer(settings.DATA_PATH)
# initializing api and middlewares
api = falcon.API(middleware=[
AuthMiddleware(),
RequireJSON(),
JSONTranslator(),
])
# setting error handler
api.add_error_handler(AnalyzerError, AnalyzerError.handle)
# adding routes
api.add_route('/feature', FeatureResource(analyzer))
api.add_route('/feature/{feat}', FeatureDetailResource(analyzer))
api.add_route('/train', TrainResource(analyzer))
api.add_route('/classify', ClassifyResource(analyzer))
api.add_route('/build', BuildResource(analyzer))
if __name__ == '__main__':
httpd = simple_server.make_server('127.0.0.1',
os.getenv('PORT', 8000), api)
httpd.serve_forever()