File tree 10 files changed +31
-24
lines changed
(topic-detail)/topics/[slug]
posts/(post-detail)/[category]/[slug]
10 files changed +31
-24
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import type { Metadata } from 'next'
4
4
import { QueryHydrate } from '~/components/common/QueryHydrate'
5
5
import { NormalContainer } from '~/components/layout/container/Normal'
6
6
import { isShallowEqualArray } from '~/lib/_'
7
- import { attachUA } from '~/lib/attach-ua'
7
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
8
8
import { getQueryClient } from '~/lib/query-client.server'
9
9
10
10
import { getTopicQuery } from './query'
@@ -14,7 +14,7 @@ export const generateMetadata = async (
14
14
slug : string
15
15
} > ,
16
16
) => {
17
- attachUA ( )
17
+ attachUAAndRealIp ( )
18
18
const queryClient = getQueryClient ( )
19
19
20
20
const query = getTopicQuery ( props . params . slug )
@@ -30,7 +30,7 @@ export default async function Layout(
30
30
slug : string
31
31
} > ,
32
32
) {
33
- attachUA ( )
33
+ attachUAAndRealIp ( )
34
34
const queryClient = getQueryClient ( )
35
35
const query = getTopicQuery ( props . params . slug )
36
36
const queryKey = query . queryKey
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import type { Metadata } from 'next'
4
4
import { QueryHydrate } from '~/components/common/QueryHydrate'
5
5
import { NormalContainer } from '~/components/layout/container/Normal'
6
6
import { isShallowEqualArray } from '~/lib/_'
7
- import { attachUA } from '~/lib/attach-ua'
7
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
8
8
import { getQueryClient } from '~/lib/query-client.server'
9
9
10
10
import { topicsQuery } from './query'
@@ -18,7 +18,7 @@ export default async function Layout(
18
18
slug : string
19
19
} > ,
20
20
) {
21
- attachUA ( )
21
+ attachUAAndRealIp ( )
22
22
const queryClient = getQueryClient ( )
23
23
24
24
await queryClient . fetchQuery ( topicsQuery )
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpT
9
9
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
10
10
import { CommentAreaRootLazy } from '~/components/widgets/comment'
11
11
import { TocFAB } from '~/components/widgets/toc/TocFAB'
12
- import { attachUA } from '~/lib/attach-ua'
12
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
13
13
import { getOgUrl } from '~/lib/helper.server'
14
14
import { getSummaryFromMd } from '~/lib/markdown'
15
15
import { getQueryClient } from '~/lib/query-client.server'
@@ -32,7 +32,7 @@ export const generateMetadata = async ({
32
32
} ) : Promise < Metadata > => {
33
33
const { slug } = params
34
34
try {
35
- attachUA ( )
35
+ attachUAAndRealIp ( )
36
36
const data = await getQueryClient ( ) . fetchQuery ( queries . page . bySlug ( slug ) )
37
37
const { title, text } = data
38
38
const description = getSummaryFromMd ( text ?? '' )
@@ -67,7 +67,7 @@ interface PageParams {
67
67
}
68
68
69
69
export default async ( props : NextPageParams < PageParams > ) => {
70
- attachUA ( )
70
+ attachUAAndRealIp ( )
71
71
const {
72
72
params : { slug } ,
73
73
} = props
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import type { Metadata } from 'next'
4
4
import { QueryHydrate } from '~/components/common/QueryHydrate'
5
5
import { NormalContainer } from '~/components/layout/container/Normal'
6
6
import { isShallowEqualArray } from '~/lib/_'
7
- import { attachUA } from '~/lib/attach-ua'
7
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
8
8
import { getQueryClient } from '~/lib/query-client.server'
9
9
10
10
import { getPageBySlugQuery } from './query'
@@ -14,7 +14,7 @@ export const generateMetadata = async (
14
14
slug : string
15
15
} > ,
16
16
) => {
17
- attachUA ( )
17
+ attachUAAndRealIp ( )
18
18
const queryClient = getQueryClient ( )
19
19
20
20
const query = getPageBySlugQuery ( props . params . slug )
@@ -30,7 +30,7 @@ export default async function Layout(
30
30
slug : string
31
31
} > ,
32
32
) {
33
- attachUA ( )
33
+ attachUAAndRealIp ( )
34
34
const queryClient = getQueryClient ( )
35
35
const query = getPageBySlugQuery ( props . params . slug )
36
36
const queryKey = query . queryKey
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import { ScrollTop } from '~/components/common/ScrollTop'
13
13
import { Root } from '~/components/layout/root/Root'
14
14
import { SearchPanelWithHotKey } from '~/components/widgets/shared/SearchFAB'
15
15
import { TocAutoScroll } from '~/components/widgets/toc/TocAutoScroll'
16
- import { attachUA } from '~/lib/attach-ua'
16
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
17
17
import { sansFont , serifFont } from '~/lib/fonts'
18
18
import { getQueryClient } from '~/lib/query-client.server'
19
19
import { AggregationProvider } from '~/providers/root/aggregation-data-provider'
@@ -118,7 +118,7 @@ type Props = {
118
118
}
119
119
120
120
export default async function RootLayout ( props : Props ) {
121
- attachUA ( )
121
+ attachUAAndRealIp ( )
122
122
const { children } = props
123
123
124
124
const queryClient = getQueryClient ( )
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { NoteFontSettingFab } from '~/components/widgets/note/NoteFontFab'
8
8
import { NoteMainContainer } from '~/components/widgets/note/NoteMainContainer'
9
9
import { TocFAB } from '~/components/widgets/toc/TocFAB'
10
10
import { REQUEST_QUERY } from '~/constants/system'
11
- import { attachUA } from '~/lib/attach-ua'
11
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
12
12
import { getOgUrl } from '~/lib/helper.server'
13
13
import { getSummaryFromMd } from '~/lib/markdown'
14
14
import { getQueryClient } from '~/lib/query-client.server'
@@ -31,7 +31,7 @@ export const generateMetadata = async ({
31
31
}
32
32
} ) : Promise < Metadata > => {
33
33
try {
34
- attachUA ( )
34
+ attachUAAndRealIp ( )
35
35
const { data } = await getQueryClient ( ) . fetchQuery (
36
36
queries . note . byNid ( params . id ) ,
37
37
)
@@ -68,7 +68,7 @@ export default async (
68
68
id : string
69
69
} > ,
70
70
) => {
71
- attachUA ( )
71
+ attachUAAndRealIp ( )
72
72
const header = headers ( )
73
73
const searchParams = new URLSearchParams ( header . get ( REQUEST_QUERY ) || '' )
74
74
const id = props . params . id
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpT
9
9
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
10
10
import { CommentAreaRootLazy } from '~/components/widgets/comment'
11
11
import { TocFAB } from '~/components/widgets/toc/TocFAB'
12
- import { attachUA } from '~/lib/attach-ua'
12
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
13
13
import { getOgUrl } from '~/lib/helper.server'
14
14
import { getSummaryFromMd } from '~/lib/markdown'
15
15
import { getQueryClient } from '~/lib/query-client.server'
@@ -26,7 +26,7 @@ export const generateMetadata = async ({
26
26
} ) : Promise < Metadata > => {
27
27
const { category, slug } = params
28
28
try {
29
- attachUA ( )
29
+ attachUAAndRealIp ( )
30
30
const data = await getQueryClient ( ) . fetchQuery (
31
31
queries . post . bySlug ( category , slug ) ,
32
32
)
@@ -69,7 +69,7 @@ interface PageParams {
69
69
}
70
70
71
71
export default async ( props : NextPageParams < PageParams > ) => {
72
- attachUA ( )
72
+ attachUAAndRealIp ( )
73
73
const {
74
74
params : { category, slug } ,
75
75
} = props
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { TimelineType } from '@mx-space/api-client'
7
7
import { QueryHydrate } from '~/components/common/QueryHydrate'
8
8
import { SearchFAB } from '~/components/widgets/shared/SearchFAB'
9
9
import { REQUEST_QUERY } from '~/constants/system'
10
- import { attachUA } from '~/lib/attach-ua'
10
+ import { attachUAAndRealIp } from '~/lib/attach-ua'
11
11
import { getQueryClient } from '~/lib/query-client.server'
12
12
import { apiClient } from '~/lib/request'
13
13
@@ -16,7 +16,7 @@ export const metadata = {
16
16
}
17
17
18
18
export default async ( props : NextPageParams < { } , PropsWithChildren > ) => {
19
- attachUA ( )
19
+ attachUAAndRealIp ( )
20
20
const header = headers ( )
21
21
const query = header . get ( REQUEST_QUERY )
22
22
Original file line number Diff line number Diff line change @@ -5,11 +5,18 @@ import { $axios } from '~/lib/request'
5
5
6
6
import PKG from '../../package.json'
7
7
8
- export const attachUA = ( ) => {
8
+ export const attachUAAndRealIp = ( ) => {
9
9
if ( ! isServer ) return
10
10
const { get } = headers ( )
11
11
12
12
const ua = get ( 'user-agent' )
13
+ const ip =
14
+ get ( 'x-real-ip' ) ||
15
+ get ( 'x-forwarded-for' ) ||
16
+ get ( 'remote-addr' ) ||
17
+ get ( 'cf-connecting-ip' )
18
+ $axios . defaults . headers . common [ 'X-Real-IP' ] = ip
19
+ $axios . defaults . headers . common [ 'X-Forwarded-For' ] = ip
13
20
$axios . defaults . headers . common [
14
21
'User-Agent'
15
22
] = `${ ua } NextJS/v${ PKG . dependencies . next } ${ PKG . name } /${ PKG . version } `
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import type { Metadata } from 'next'
6
6
import { getQueryClient } from '~/lib/query-client.server'
7
7
import { queries } from '~/queries/definition'
8
8
9
- import { attachUA } from './attach-ua'
9
+ import { attachUAAndRealIp } from './attach-ua'
10
10
11
11
export const defineMetadata = < T extends Record < string , string > > (
12
12
fn : (
@@ -17,7 +17,7 @@ export const defineMetadata = <T extends Record<string, string>>(
17
17
const handler = async ( { params } : { params : T } ) : Promise < Metadata > => {
18
18
const getData = async ( ) => {
19
19
const queryClient = getQueryClient ( )
20
- attachUA ( )
20
+ attachUAAndRealIp ( )
21
21
return await queryClient . fetchQuery ( {
22
22
...queries . aggregation . root ( ) ,
23
23
} )
You can’t perform that action at this time.
0 commit comments