diff --git a/README.md b/README.md index 9bd1269..6b4bfc1 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,17 @@ # Elstat -**TODO: Add description** +Status page software. -## Installation +## Installing -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `elstat` to your list of dependencies in `mix.exs`: - -```elixir -def deps do - [ - {:elstat, "~> 0.1.0"} - ] -end +``` +git clone https://gitlab.com/elixire/elstat +cd elstat +python3.6 -m pip install -Ur requirements.txt ``` -Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) -and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at [https://hexdocs.pm/elstat](https://hexdocs.pm/elstat). +## Run +``` +python3.6 run.py +``` diff --git a/blueprints/__init__.py b/blueprints/__init__.py new file mode 100644 index 0000000..918d21c --- /dev/null +++ b/blueprints/__init__.py @@ -0,0 +1 @@ +from .api import bp as api diff --git a/blueprints/api.py b/blueprints/api.py new file mode 100644 index 0000000..3a0bcdc --- /dev/null +++ b/blueprints/api.py @@ -0,0 +1,13 @@ +from sanic import Blueprint, response + +bp = Blueprint(__name__) + + +@bp.get('/api/current_status') +async def get_cur_status(request): + pass + + +@bp.get('/api/status') +async def get_full_status(request): + pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0619533 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/channelcat/sanic@f9b29fd7e746301624d3d1a3501b1c47287eb297 +sanic-cors==0.9.4 +aiohttp==3.3.2 diff --git a/run.py b/run.py new file mode 100644 index 0000000..b87ee1a --- /dev/null +++ b/run.py @@ -0,0 +1,43 @@ +import logging +import sqlite3 + +import aiohttp +from sanic import Sanic, response +from sanic_cors import CORS +from sanic.exceptions import NotFound, FileNotFound + +import config + +logging.basicConfig(level=logging.INFO) +app = Sanic() +app.cfg = config +CORS(app, automatic_options=True) + + +@app.listener('before_server_start') +async def _app_start(refapp, loop): + refapp.session = aiohttp.ClientSession(loop=loop) + refapp.conn = sqlite3.connect('elstat.db') + + +@app.listener('after_server_stop') +async def _app_stop(refapp, _loop): + refapp.conn.close() + + +@app.exception(Exception) +async def _handle_exc(request, exception): + status_code = 404 if isinstance(exception, (NotFound, FileNotFound)) \ + else 500 + + return response.json({ + 'error': True, + 'message': repr(exception) + }, status=status_code) + + +if __name__ == '__main__': + app.static('/', './priv/frontend/build') + app.static('/', './priv/frontend/build/index.html') + + app.run(port=config.PORT)