Skip to content

Commit

Permalink
add web back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Aug 20, 2024
1 parent ff2474e commit 75ead9c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions web/web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from flask import Flask, request, render_template, send_from_directory
from jamesql import JameSQL
from jamesql.index import GSI_INDEX_STRATEGIES
import json
from tqdm import tqdm

app = Flask(__name__)

index = JameSQL()

with open("tests/fixtures/documents.json") as f:
documents = json.load(f)

for document in tqdm(documents):
document = document.copy()
index.add(document)

@app.route("/", methods=["GET", "POST"])
def search():
if request.method == "POST":
query = request.json
# convert to a python dictionary
result = index.search(query)
return result

return render_template("index.html")

# serve ./ace-builds
@app.route("/ace-builds/<path:path>")
def ace(path):
return send_from_directory("ace-builds", path)

if __name__ == "__main__":
app.run(debug=True)

0 comments on commit 75ead9c

Please sign in to comment.