Redirect empty GET with request to client address
This commit is contained in:
parent
f78ed7592d
commit
1fa64feefc
10
app/main.py
10
app/main.py
@ -6,7 +6,8 @@ from typing import Annotated, Optional, Union
|
|||||||
|
|
||||||
import geoip2.database
|
import geoip2.database
|
||||||
from geoip2.errors import AddressNotFoundError
|
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
|
from pydantic import BaseModel
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@ -87,3 +88,10 @@ async def root_get(ipaddress: Annotated[Union[IPv4Address,IPv6Address],
|
|||||||
return locations.pop()
|
return locations.pop()
|
||||||
response.status_code = status.HTTP_404_NOT_FOUND
|
response.status_code = status.HTTP_404_NOT_FOUND
|
||||||
return GeoLocation()
|
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user