unshorten/server/src/main.py

30 lines
620 B
Python
Raw Normal View History

2024-04-13 22:41:22 +00:00
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from typing import Optional
from urllib.parse import urlparse
SHORTEN_DOMAINS = [
't.co'
]
app = FastAPI(docs_url=None, redoc_url=None)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["GET"]
)
@app.get('/')
2024-04-13 23:31:00 +00:00
async def unshorten_url(url: Optional[str] = None):
2024-04-13 22:41:22 +00:00
if url is None:
return {"error": "no url provided"}
domain = urlparse(url).netloc
if domain in SHORTEN_DOMAINS:
return {"result": "shortened url"}
else:
return {"error": f"cannot shorten {url}"}