Skip to content

Commit

Permalink
Add util router with client_ip and headers endpoints for connec…
Browse files Browse the repository at this point in the history
…tion debugging

Allows all forwarded IPs to get real client IP address instead of proxy IP
  • Loading branch information
NeonDaniel committed May 15, 2024
1 parent c57270b commit ac31046
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions neon_hana/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from neon_hana.app.routers.llm import llm_route
from neon_hana.app.routers.mq_backend import mq_route
from neon_hana.app.routers.auth import auth_route
from neon_hana.app.routers.util import util_route
from neon_hana.version import __version__


Expand All @@ -45,5 +46,6 @@ def create_app(config: dict):
app.include_router(proxy_route)
app.include_router(mq_route)
app.include_router(llm_route)
app.include_router(util_route)

return app
2 changes: 1 addition & 1 deletion neon_hana/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
config = Configuration().get("hana", {})
app = create_app(config)
uvicorn.run(app, host=config.get('server_host', "0.0.0.0"),
port=config.get('port', 8080))
port=config.get('port', 8080), forwarded_allow_ips="*")


if __name__ == "__main__":
Expand Down
40 changes: 40 additions & 0 deletions neon_hana/app/routers/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2021 Neongecko.com Inc.
# BSD-3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from fastapi import APIRouter, Request
from starlette.datastructures import Headers

util_route = APIRouter(prefix="/util", tags=["utilities"])


@util_route.get("/client_ip")
async def api_client_ip(request: Request) -> str:
return request.client.host


@util_route.get("/headers")
async def api_headers(request: Request) -> Headers:
return request.headers

0 comments on commit ac31046

Please sign in to comment.