miro: make proxy image thought Caddy

This commit is contained in:
ZhymabekRoman 2024-07-22 11:40:31 +05:00
parent 3876fef698
commit 1151e9388f
5 changed files with 21 additions and 5 deletions

View file

@ -162,6 +162,11 @@
respond "Access denied" 403 respond "Access denied" 403
} }
route @miro/* {
uri replace @miro/ /
reverse_proxy https://miro.medium.com
}
route /* { route /* {
reverse_proxy web:7080 reverse_proxy web:7080
} }

View file

@ -5,6 +5,11 @@
{{ template }} {{ template }}
route @miro/* {
uri replace @miro/ /
reverse_proxy https://miro.medium.com
}
route /* { route /* {
reverse_proxy web:7080 reverse_proxy web:7080
} }

View file

@ -6,6 +6,11 @@ freedium.cfd {
{{ template }} {{ template }}
route @miro/* {
uri replace @miro/ /
reverse_proxy https://miro.medium.com
}
route /* { route /* {
reverse_proxy web:7080 reverse_proxy web:7080
} }

View file

@ -39,10 +39,10 @@ async def route_processing(path: str, request: Request):
if key_data != config.ADMIN_SECRET_KEY: if key_data != config.ADMIN_SECRET_KEY:
return JSONResponse({"message": f"Wrong secret key: {key_data}"}, status_code=403) return JSONResponse({"message": f"Wrong secret key: {key_data}"}, status_code=403)
if path.startswith("@miro/"): # if path.startswith("@miro/"):
miro_data = path.removeprefix("@miro/") # miro_data = path.removeprefix("@miro/")
return await miro_proxy(miro_data) # return await miro_proxy(miro_data)
elif path.startswith("render_iframe/"): if path.startswith("render_iframe/"):
iframe_id = path.removeprefix("render_iframe/") iframe_id = path.removeprefix("render_iframe/")
return await iframe_proxy(iframe_id) return await iframe_proxy(iframe_id)

View file

@ -8,8 +8,9 @@ from bs4 import BeautifulSoup, Comment
IFRAME_HEADERS = {"Access-Control-Allow-Origin": "*", "X-Frame-Options": "SAMEORIGIN"} IFRAME_HEADERS = {"Access-Control-Allow-Origin": "*", "X-Frame-Options": "SAMEORIGIN"}
@trace @trace
async def iframe_proxy(iframe_id): async def iframe_proxy(iframe_id: str):
# How Medium embeds works: https://stackoverflow.com/questions/56594766/medium-embed-ly-notifyresize-does-not-work-on-safari # How Medium embeds works: https://stackoverflow.com/questions/56594766/medium-embed-ly-notifyresize-does-not-work-on-safari
async with aiohttp.ClientSession() as client: async with aiohttp.ClientSession() as client:
request = await client.get( request = await client.get(