Skip to content

Instantly share code, notes, and snippets.

@oeway
Created March 24, 2020 12:00
Show Gist options
  • Save oeway/01dd961ca56d1a8f1ce4bc30f7d79b1e to your computer and use it in GitHub Desktop.
Save oeway/01dd961ca56d1a8f1ce4bc30f7d79b1e to your computer and use it in GitHub Desktop.

Setup

pip intall flask
pip install -U flask-cors

Run

env FLASK_APP=run_flask.py flask run
<docs lang="markdown">
[TODO: write documentation for this plugin.]
</docs>
<config lang="json">
{
"name": "MyFirstPlugin",
"type": "window",
"tags": [],
"ui": "",
"version": "0.1.0",
"cover": "",
"description": "[TODO: describe this plugin with one sentence.]",
"icon": "extension",
"inputs": null,
"outputs": null,
"api_version": "0.1.7",
"env": "",
"permissions": [],
"requirements": [],
"dependencies": [],
"defaults": {"w": 20, "h": 10}
}
</config>
<script lang="javascript">
class ImJoyPlugin {
async setup() {
api.log('initialized')
}
async run(ctx) {
window.getData = async function(){
const response = await fetch("http://127.0.0.1:5000/");
const data = await response.text()
api.alert('Your data is here:' + data)
}
}
}
api.export(new ImJoyPlugin())
</script>
<window lang="html">
<div>
<button onclick="getData()">Get Data from flask</button>
<img id="myimage"></img>
</div>
</window>
<style lang="css">
</style>
from flask import Flask, escape, request
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/')
def hello():
name = request.args.get("name", "World")
return f'Hello, {escape(name)}!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment