feat: integrate getClientIPAddress utility for improved IP address retrieval

This commit is contained in:
Ardeman
2025-03-20 12:31:51 +08:00
parent 6edca07fa6
commit 305c2cf140
4 changed files with 234 additions and 8 deletions
+2 -4
View File
@@ -1,4 +1,5 @@
import { isRouteErrorResponse } from 'react-router'
import { getClientIPAddress } from 'remix-utils/get-client-ip-address'
import { stripHtml } from 'string-strip-html'
import { getCategories } from '~/apis/common/get-categories'
@@ -13,10 +14,7 @@ import type { Route } from './+types/_news.detail.$slug'
export const loader = async ({ request, params }: Route.LoaderArgs) => {
const userAgent = request.headers.get('user-agent')
const ipAddress =
request.headers.get('cf-connecting-ip') ||
request.headers.get('x-forwarded-for') ||
'localhost'
const ipAddress = getClientIPAddress(request) || 'localhost'
const { userToken: accessToken } = await handleCookie(request)
let userData
if (accessToken) {
+2 -4
View File
@@ -1,4 +1,5 @@
import { data } from 'react-router'
import { getClientIPAddress } from 'remix-utils/get-client-ip-address'
import { XiorError } from 'xior'
import { createLogAdsRequest } from '~/apis/news/create-log-ads'
@@ -8,10 +9,7 @@ import type { Route } from './+types/actions.log.ads.$id'
export const action = async ({ request, params }: Route.ActionArgs) => {
const userAgent = request.headers.get('user-agent')
const ipAddress =
request.headers.get('cf-connecting-ip') ||
request.headers.get('x-forwarded-for') ||
'localhost'
const ipAddress = getClientIPAddress(request) || 'localhost'
const { userToken: accessToken } = await handleCookie(request)
const { id } = params
try {