diff --git a/app/main.py b/app/main.py index 6322685..8feb465 100644 --- a/app/main.py +++ b/app/main.py @@ -6,7 +6,8 @@ from typing import Annotated, Optional, Union import geoip2.database from geoip2.errors import AddressNotFoundError -from fastapi import FastAPI, Path, Body, Response, status +from fastapi import FastAPI, Path, Body, Request, Response, status +from fastapi.responses import RedirectResponse from pydantic import BaseModel app = FastAPI() @@ -87,3 +88,10 @@ async def root_get(ipaddress: Annotated[Union[IPv4Address,IPv6Address], return locations.pop() response.status_code = status.HTTP_404_NOT_FOUND return GeoLocation() + +@app.get("/") +def root_redirect(req: Request) -> RedirectResponse: + ''' + Redirect empty request using REMOTE_ADDR + ''' + return RedirectResponse(url= str(req.url) + str(req.client.host))