Skip to content

Commit

Permalink
fixed a bug with trying to see the forwarded IP
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigfried committed Mar 8, 2024
1 parent 12a0bd1 commit f13b6c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions backend/api_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Api_logger:
def __init__(self):
pass

async def start_rpt(self, request: Request, params: Dict, debugIP=False):
async def start_rpt(self, request: Request, params: Dict):
self.start_time = time.time()
rpt = {}
url = request.url
Expand All @@ -32,7 +32,7 @@ async def start_rpt(self, request: Request, params: Dict, debugIP=False):

rpt['host'] = os.getenv('HOSTENV', gethostname())

ip = await get_ip_from_request(request, debugIP)
ip = await get_ip_from_request(request)
rpt['client'] = await client_location(ip)

rpt['schema'] = get_schema_name()
Expand Down Expand Up @@ -101,10 +101,9 @@ async def log_error(self, e):
await self.complete_log_record()


async def get_ip_from_request(request: Request, debugIP=True) -> str:
async def get_ip_from_request(request: Request) -> str:
forwarded_for: Optional[str] = request.headers.get('X-Forwarded-For')
if debugIP:
print((forwarded_for or 'no forward') + '; ' + request.client.host)
print((forwarded_for or 'no forward') + '; ' + request.client.host)
if forwarded_for:
# The header can contain multiple IP addresses, so take the first one
ip = forwarded_for.split(',')[0]
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def _get_csets(request: Request, codeset_ids: Union[str, None] = Query(def
"""Route for: get_csets()"""
requested_codeset_ids = parse_codeset_ids(codeset_ids)
rpt = Api_logger()
await rpt.start_rpt(request, params={'codeset_ids': requested_codeset_ids}, debugIP=True)
await rpt.start_rpt(request, params={'codeset_ids': requested_codeset_ids})

try:
csets = get_csets(requested_codeset_ids)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/N3CRecommended.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const N3CComparisonRpt = () => {
try {
// const rows = await dataGetter.axiosCall('n3c-comparison-rpt', {sendAlert: false, });
let url = backend_url('n3c_comparison_rpt');
let data = await dataGetter.fetchAndCacheItems(dataGetter.apiCalls.n3c_comparison_rpt);
let rows = await dataGetter.fetchAndCacheItems(dataGetter.apiCalls.n3c_comparison_rpt);
let concept_ids = uniq(flatten(rows.map(row => [...(row.added), ...(row.removed)])));
const concepts = await dataGetter.fetchAndCacheItems(dataGetter.apiCalls.concepts, concept_ids);
setData({rows, concepts});
Expand Down

0 comments on commit f13b6c2

Please sign in to comment.