DeaD_EyE

whatismyip with starlette behind a reverse proxy

Apr 13th, 2020
196
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from starlette.applications import Starlette
  2. from starlette.responses import JSONResponse
  3. import uvicorn
  4.  
  5.  
  6. app = Starlette(debug=False)
  7.  
  8.  
  9. @app.route("/whatismyip")
  10. @app.route("/")
  11. async def homepage(request):
  12.     response = JSONResponse({"ip": request.headers["x-real-ip"]})
  13.     return response
  14.  
  15.  
  16.  
  17. if __name__ == "__main__":
  18.     uvicorn.run("main:app", host="127.0.0.1", port=5001, log_level="info")
RAW Paste Data