Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(main.py): Incompatibility issues with Quart and Quart-CORS #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# Keep track of todo's. Does not persist if Python session is restarted.
_TODOS = {}

@app.post("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["POST"])
async def add_todo(username):
request = await quart.request.get_json(force=True)
if username not in _TODOS:
_TODOS[username] = []
_TODOS[username].append(request["todo"])
return quart.Response(response='OK', status=200)

@app.get("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["GET"])
async def get_todos(username):
return quart.Response(response=json.dumps(_TODOS.get(username, [])), status=200)

@app.delete("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["DELETE"])
async def delete_todo(username):
request = await quart.request.get_json(force=True)
todo_idx = request["todo_idx"]
Expand All @@ -30,24 +30,24 @@ async def delete_todo(username):
_TODOS[username].pop(todo_idx)
return quart.Response(response='OK', status=200)

@app.get("/logo.png")
@app.route("/logo.png", methods=["GET"])
async def plugin_logo():
filename = 'logo.png'
return await quart.send_file(filename, mimetype='image/png')
return await quart.send_file(filename)

@app.get("/.well-known/ai-plugin.json")
@app.route("/.well-known/ai-plugin.json", methods=["GET"])
async def plugin_manifest():
host = request.headers['Host']
with open("./.well-known/ai-plugin.json") as f:
text = f.read()
return quart.Response(text, mimetype="text/json")
return quart.Response(text, content_type="text/json")

@app.get("/openapi.yaml")
@app.route("/openapi.yaml", methods=["GET"])
async def openapi_spec():
host = request.headers['Host']
with open("openapi.yaml") as f:
text = f.read()
return quart.Response(text, mimetype="text/yaml")
return quart.Response(text, content_type="text/yaml")

def main():
app.run(debug=True, host="0.0.0.0", port=5003)
Expand Down