from fastapi import FastAPI, Request, Response
filenames = ["js/sketch.js"]
contents = '\n'.join([f"" for x in filenames])
app = FastAPI()
@app.middleware("http")
async def insert_js(request: Request, call_next):
path = request.scope['path'] # get the request route
response = await call_next(request)
if path == "/":
response_body = ""
async for chunk in response.body_iterator:
response_body += chunk.decode()
some_javascript = """
"""
response_body = response_body.replace("", some_javascript + "")
response_body = response_body.replace("