summaryrefslogtreecommitdiff
path: root/app/api/test/headers/route.ts
blob: 70c14564122c18ab0da55baa53a25014ca74a987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { NextRequest, NextResponse } from 'next/server';
import { headers } from 'next/headers';

/**
 * 리버스 프록시 헤더 전달 테스트 API
 * 
 * 접속 방법:
 * - https://shidataroom.com/api/test/headers
 * - https://partners.sevcp.com/api/test/headers
 * - https://sevcp.com/api/test/headers
 * 
 * 각 도메인에서 헤더가 올바르게 전달되는지 확인
 */
export async function GET(request: NextRequest) {
  const headersList = await headers();
  
  // 중요한 헤더들 수집
  const host = headersList.get('host');
  const xForwardedProto = headersList.get('x-forwarded-proto');
  const xForwardedHost = headersList.get('x-forwarded-host');
  const xForwardedFor = headersList.get('x-forwarded-for');
  const xRealIp = headersList.get('x-real-ip');
  
  // 현재 계산된 origin
  const proto = xForwardedProto || 'http';
  const computedOrigin = `${proto}://${host}`;
  
  // request.nextUrl의 origin (Next.js가 인식하는 origin)
  const nextUrlOrigin = request.nextUrl.origin;
  
  return NextResponse.json({
    success: true,
    message: '리버스 프록시 헤더 정보',
    headers: {
      host,
      'x-forwarded-proto': xForwardedProto,
      'x-forwarded-host': xForwardedHost,
      'x-forwarded-for': xForwardedFor,
      'x-real-ip': xRealIp,
    },
    computed: {
      origin: computedOrigin,
      nextUrlOrigin,
      isCorrect: computedOrigin === nextUrlOrigin,
    },
    recommendations: {
      dmz_nginx: {
        required: [
          'proxy_set_header Host $host;',
          'proxy_set_header X-Forwarded-Proto $scheme;',
          'proxy_set_header X-Forwarded-Host $host;',
          'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;',
          'proxy_set_header X-Real-IP $remote_addr;',
        ]
      },
      ap_nginx: {
        required: [
          'proxy_set_header Host $host;',
          'proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;',
          'proxy_set_header X-Forwarded-Host $http_x_forwarded_host;',
          'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;',
          'proxy_set_header X-Real-IP $http_x_real_ip;',
        ]
      }
    },
    test: {
      description: '각 도메인에서 이 API를 호출하여 헤더가 올바른지 확인하세요',
      expected: {
        'shidataroom.com': 'computed.origin should be "https://shidataroom.com"',
        'partners.sevcp.com': 'computed.origin should be "https://partners.sevcp.com"',
        'sevcp.com': 'computed.origin should be "https://sevcp.com"',
      }
    }
  }, {
    headers: {
      'Content-Type': 'application/json',
    }
  });
}