diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8e9d62 --- /dev/null +++ b/.gitignore @@ -0,0 +1,123 @@ + +# Created by https://www.gitignore.io/api/python,virtualenv +# Edit at https://www.gitignore.io/?templates=python,virtualenv + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### VirtualEnv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +pyvenv.cfg +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pip-selfcheck.json + +# End of https://www.gitignore.io/api/python,virtualenv diff --git a/static/index.html b/index.html similarity index 100% rename from static/index.html rename to index.html diff --git a/src/main.py b/main.py similarity index 76% rename from src/main.py rename to main.py index d005b2f..ffb0f67 100644 --- a/src/main.py +++ b/main.py @@ -6,20 +6,23 @@ routes.static('/static', 'static') admintoken = "ae33fd8cc4fdcb1ff50ba42ff48046a7" +CLIENT_REGEX = r'/{client:[a-zA-Z0-9]{16}}' + meta_dict = {} -@routes.get(r'/{client:[a-z][a-z][a-z][a-z][a-z]}') + +@routes.get(CLIENT_REGEX) async def handler(request): - #session = request.match_info.get("session", "") client = request.match_info.get("client", "") print(f"{client=} accessed") - return aiohttp.web.FileResponse('static/ui.html') + return aiohttp.web.FileResponse('ui.html') async def handle_request(data, client): return "foo" in data -@routes.post('/{client}/api') + +@routes.post(CLIENT_REGEX + '/api') async def handler(request): client = request.match_info.get("client", "") @@ -27,19 +30,21 @@ async def handler(request): ok = await handle_request(data, client) if ok: - #return aiohttp.web.json_response({"x" : x}) + # return aiohttp.web.json_response({"x" : x}) return aiohttp.web.Response(status=200) else: return aiohttp.web.Response(status=400) + @routes.get(f"/api/{admintoken}") async def handler(request): return aiohttp.web.json_response(meta_dict) + @routes.get('/') async def handler(request): del request # unused - return aiohttp.web.FileResponse('static/index.html') + return aiohttp.web.FileResponse('index.html') if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f179af2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +aiohttp==3.6.2 \ No newline at end of file diff --git a/static/ui.html b/ui.html similarity index 100% rename from static/ui.html rename to ui.html