Skip to content

Commit

Permalink
Add Server framework
Browse files Browse the repository at this point in the history
  • Loading branch information
eflynch committed Jul 6, 2020
1 parent fa5b064 commit 339f535
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 27 deletions.
175 changes: 148 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,176 @@
###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

# 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###

Expand All @@ -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
16 changes: 16 additions & 0 deletions server/api.py
Original file line number Diff line number Diff line change
@@ -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({
})
29 changes: 29 additions & 0 deletions server/magnolial.py
Original file line number Diff line number Diff line change
@@ -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')
20 changes: 20 additions & 0 deletions server/reactstub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

def reactstub(title, stylesheets=[], scripts=[], bootstrap="{}", copyright="© Evan F Lynch 2020"):
css = map(lambda s: '<link rel="stylesheet" type="text/css" href="/static/{}">'.format(s), stylesheets)
js = map(lambda s: '<script src="/static/{}"></script>'.format(s), scripts)
return """
<!-- HTML stub that loads ReactJS -->
<!-- {} -->
<head>
<title>{}</title>
<meta charset="UTF-8">
<link rel="shortcut icon" href="/static/app/favicon.ico" />
<script>window.bootstrap = JSON.parse('{}'); </script>
{}
{}
</head>
<body>
<div id="header"></div>
<div id="content"></div>
</body>
""".format(copyright, title, bootstrap, "\n".join(css), "\n".join(js))
2 changes: 2 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
psycopg2-binary
1 change: 1 addition & 0 deletions server/static/app

0 comments on commit 339f535

Please sign in to comment.