diff --git a/README.md b/README.md index 87cfaaf..fecc845 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,11 @@ adapt its behavior: means `localhost` only). * `PORT=` to specify the port to listen on (defaults to `8081`). +### Serving + +You can use the `wsgi.py` script at the root of the git repository to serve +the server side part. + ## Contributing diff --git a/server/__main__.py b/server/__main__.py index 5bba1c9..e9bd537 100644 --- a/server/__main__.py +++ b/server/__main__.py @@ -11,7 +11,7 @@ from server.jsonapi import DateAwareJSONEncoder from server.models import db, Report -if __name__ == "__main__": +def init(): db.connect() db.create_tables([Report]) @@ -22,6 +22,11 @@ if __name__ == "__main__": json_dumps=functools.partial(json.dumps, cls=DateAwareJSONEncoder) ) ) + + +if __name__ == "__main__": + init() + bottle.run( host=os.environ.get('HOST', '127.0.0.1'), port=int(os.environ.get('PORT', '8081')) diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..f378aeb --- /dev/null +++ b/wsgi.py @@ -0,0 +1,13 @@ +# coding: utf-8 +""" +Expose a WSGI-compatible application to serve with a webserver. +""" +from __future__ import absolute_import, print_function, unicode_literals + +import bottle + +from server.__main__ import init + + +init() +application = app = bottle.default_app()