11# -*- coding: utf-8 -*-
22from __future__ import absolute_import, print_function
33
4+ import os
5+ import mimetypes
6+
47import falcon
58from wsgiref import simple_server
69
@@ -17,6 +20,17 @@ class NotFoundError(object):
1720 description)
1821
1922
23+ class StaticAdapter(object):
24+
25+ def __call__(self, req, resp, filename):
26+ file_path = os.path.join(os.path.dirname(__file__), "static/%s" % filename)
27+ file_type = mimetypes.guess_type(file_path)[0]
28+ resp.status = falcon.HTTP_200
29+ resp.content_type = file_type
30+ with open(file_path, 'r') as f:
31+ resp.body = f.read()
32+
33+
2034def http_error_serializer(req, resp, exception):
2135 representation = None
2236 preferred = req.client_prefers(('application/x-yaml',
@@ -46,6 +60,8 @@ def register_routes(app):
4660 url = '{ prefix} { base_url} '.format(prefix='{ {base_path} }',
4761 base_url=route.pop('url'))
4862 app.add_route(url, route.pop('resource'))
63+ static = StaticAdapter()
64+ app.add_sink(static, r'/static/(?P<filename >.*)')
4965
5066
5167if __name__ == '__main__':
0 commit comments