From 339f535e9794bdcc01b9ac40bf7c6047f2d8703d Mon Sep 17 00:00:00 2001 From: Evan Lynch Date: Mon, 6 Jul 2020 10:01:54 -0400 Subject: [PATCH] Add Server framework --- .gitignore | 175 +++++++++++++++++++++++++++++++++------- server/api.py | 16 ++++ server/magnolial.py | 29 +++++++ server/reactstub.py | 20 +++++ server/requirements.txt | 2 + server/static/app | 1 + 6 files changed, 216 insertions(+), 27 deletions(-) create mode 100644 server/api.py create mode 100644 server/magnolial.py create mode 100644 server/reactstub.py create mode 100644 server/requirements.txt create mode 120000 server/static/app diff --git a/.gitignore b/.gitignore index 9288d11..6c9b487 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,126 @@ -###Custom### -.module-cache +client/app/main.js +###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/ +*.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/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +.static_storage/ +.media/ +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + ###Node### # Logs logs *.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* # Runtime data pids *.pid *.seed +*.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov @@ -19,19 +128,49 @@ lib-cov # Coverage directory used by tools like istanbul coverage +# nyc test coverage +.nyc_output + # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release -# Dependency directory -# Commenting this out is preferred by some people, see -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- -node_modules +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next -# Users Environment Variables -.lock-wscript ###OSX### @@ -56,21 +195,3 @@ Icon Network Trash Folder Temporary Items .apdisk - - -###SublimeText### - -# cache files for sublime text -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache - -# workspace files are user-specific -*.sublime-workspace - -# project files should be checked into the repository, unless a significant -# proportion of contributors will probably not be using SublimeText -# *.sublime-project - -# sftp configuration file -sftp-config.json diff --git a/server/api.py b/server/api.py new file mode 100644 index 0000000..b7bfde9 --- /dev/null +++ b/server/api.py @@ -0,0 +1,16 @@ +from flask import Blueprint, request, jsonify + +api = Blueprint("api", __name__) + +@api.route("/", methods=['POST']) +def command(session_id): + pay_load = request.get_json() + return jsonify({ + + }) + + +@api.route("/pixels", methods=['GET']) +def state(session_id): + return jsonify({ + }) diff --git a/server/magnolial.py b/server/magnolial.py new file mode 100644 index 0000000..7e03da5 --- /dev/null +++ b/server/magnolial.py @@ -0,0 +1,29 @@ +import os +import json + +from flask import Flask + +from reactstub import reactstub + +from api import api + +app = Flask(__name__) + +app.register_blueprint(api, url_prefix="/api") + +if os.path.exists('/etc/config.json'): + with open('/etc/config.json') as config_file: + config = json.load(config_file) + + app.config['SECRET_KEY'] = config.get('SECRET_KEY') +else: + print("Warning, running without a secret") + + +@app.route("/", methods=['GET']) +def index(): + return reactstub("Magnolial", ["app/app.css", "app/font-awesome-4.5.0/css/font-awesome.min.css"], ["app/main.js"], bootstrap=json.dumps({})) + + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0') diff --git a/server/reactstub.py b/server/reactstub.py new file mode 100644 index 0000000..ce92b09 --- /dev/null +++ b/server/reactstub.py @@ -0,0 +1,20 @@ + +def reactstub(title, stylesheets=[], scripts=[], bootstrap="{}", copyright="© Evan F Lynch 2020"): + css = map(lambda s: ''.format(s), stylesheets) + js = map(lambda s: ''.format(s), scripts) + return """ + + + + {} + + + + {} + {} + + + +
+ +""".format(copyright, title, bootstrap, "\n".join(css), "\n".join(js)) diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..630d4b8 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,2 @@ +Flask +psycopg2-binary diff --git a/server/static/app b/server/static/app new file mode 120000 index 0000000..00e2721 --- /dev/null +++ b/server/static/app @@ -0,0 +1 @@ +../../client/app/ \ No newline at end of file