Skip to content

Commit

Permalink
fix ip address parse bug (only in development)
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Dec 7, 2024
1 parent 5c711f3 commit e4d1e78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
18 changes: 5 additions & 13 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ const emitAnalytics = async (req: NextRequest): Promise<void> => {

// For abs/ routes we want to send emit an event to the link gateway
if (path.startsWith('/abs')) {
const url = `${process.env.BASE_URL}/link_gateway${path.replace(
'/abs',
'',
)}`;
const url = `${process.env.BASE_URL}/link_gateway${path.replace('/abs', '')}`;
log.debug({ path, url }, 'Emitting abs route event to link gateway');

try {
Expand All @@ -133,7 +130,8 @@ const getIp = (req: NextRequest) =>
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
req.headers.get('X-Real-Ip') ||
''
)
.split(',')
.shift() || 'unknown';
Expand Down Expand Up @@ -183,21 +181,15 @@ export async function middleware(req: NextRequest) {
return loginMiddleware(req, res);
}

if (
path.startsWith('/user/account/register') ||
path.startsWith('/user/forgotpassword')
) {
if (path.startsWith('/user/account/register') || path.startsWith('/user/forgotpassword')) {
return redirectIfAuthenticated(req, res);
}

if (path.startsWith('/user/libraries') || path.startsWith('/user/settings')) {
return protectedRoute(req, res);
}

if (
path.startsWith('/user/account/verify/change-email') ||
path.startsWith('/user/account/verify/register')
) {
if (path.startsWith('/user/account/verify/change-email') || path.startsWith('/user/account/verify/register')) {
return verifyMiddleware(req, res);
}

Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/botCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const getIp = (req: NextRequest) =>
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
req.headers.get('X-Real-Ip') ||
''
)
.split(',')
.shift() || 'unknown';
Expand Down

0 comments on commit e4d1e78

Please sign in to comment.