Skip to content

Instantly share code, notes, and snippets.

@davidferguson
Created September 10, 2016 21:51
Show Gist options
  • Save davidferguson/9a5e0c18d37f32dbf8a6c8dfb39f6273 to your computer and use it in GitHub Desktop.
Save davidferguson/9a5e0c18d37f32dbf8a6c8dfb39f6273 to your computer and use it in GitHub Desktop.
Python bottle server for @all_about_code's Blockly EduPython interface
from bottle import *
app = Bottle()
@app.hook('after_request')
def enable_cors():
print("after_request hook")
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
@post('/runcode')
def do_login():
codeToRun = request.forms.get('code')
print(codeToRun)
exec(codeToRun)
@route('/<filepath:path>')
def mainPage(filepath):
print filepath
return static_file(filepath, root='./')
@route('/')
@route('')
def mainPage():
filepath = "index.html"
return static_file(filepath, root='./')
run(host='', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment