Skip to content

Latest commit

ย 

History

History
113 lines (92 loc) ยท 2.89 KB

File metadata and controls

113 lines (92 loc) ยท 2.89 KB

๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ์„ค์ • ๊ฐ€์ด๋“œ

1. Google Cloud Console ์„ค์ •

1๋‹จ๊ณ„: ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

  1. https://console.cloud.google.com/ ์ ‘์†
  2. ์ƒˆ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ (์˜ˆ: "๋ผ๋‹ˆ SQL Practice")

2๋‹จ๊ณ„: OAuth ๋™์˜ ํ™”๋ฉด ์„ค์ •

  1. ์™ผ์ชฝ ๋ฉ”๋‰ด โ†’ "APIs & Services" โ†’ "OAuth consent screen"
  2. User Type: External ์„ ํƒ
  3. ์•ฑ ์ •๋ณด ์ž…๋ ฅ:
    • App name: ๋ผ๋‹ˆ๋ฅผ ์œ„ํ•œ ์ฟผ๋ฆฌํ…Œ์ŠคํŠธ ํ”Œ๋žซํผ
    • User support email: ๋ณธ์ธ ์ด๋ฉ”์ผ
    • Developer contact: ๋ณธ์ธ ์ด๋ฉ”์ผ
  4. Scopes ์ถ”๊ฐ€:
    • .../auth/userinfo.email
    • .../auth/userinfo.profile
  5. Test users ์ถ”๊ฐ€ (๊ฐœ๋ฐœ ์ค‘์—๋Š” ๋ณธ์ธ ์ด๋ฉ”์ผ)

3๋‹จ๊ณ„: OAuth ํด๋ผ์ด์–ธํŠธ ID ์ƒ์„ฑ

  1. "Credentials" โ†’ "Create Credentials" โ†’ "OAuth client ID"
  2. Application type: Web application
  3. ์ด๋ฆ„: SQL Practice Web Client
  4. Authorized redirect URIs ์ถ”๊ฐ€:
    http://localhost:3001/auth/google/callback
    https://your-cloudflare-url.trycloudflare.com/auth/google/callback
    
  5. "Create" ํด๋ฆญ
  6. Client ID์™€ Client Secret ๋ณต์‚ฌ

2. ์„œ๋ฒ„ ์„ค์ •

.env ํŒŒ์ผ ์ˆ˜์ •

/home/sql/server/.env ํŒŒ์ผ์„ ์—ด์–ด์„œ:

GOOGLE_CLIENT_ID=๋ณต์‚ฌํ•œ_ํด๋ผ์ด์–ธํŠธ_ID
GOOGLE_CLIENT_SECRET=๋ณต์‚ฌํ•œ_์‹œํฌ๋ฆฟ
SESSION_SECRET=๋žœ๋คํ•œ_๋น„๋ฐ€ํ‚ค_์ƒ์„ฑ
CALLBACK_URL=http://localhost:3001/auth/google/callback

์„œ๋ฒ„ ์žฌ์‹œ์ž‘

cd /home/sql
pkill -f "node.*server"
cd server && NODE_OPTIONS="--max-old-space-size=8192" node server.js &

3. ํ…Œ์ŠคํŠธ

๋ธŒ๋ผ์šฐ์ €์—์„œ:

  1. http://localhost:3001/auth/google ์ ‘์†
  2. ๊ตฌ๊ธ€ ๊ณ„์ • ์„ ํƒ
  3. ๊ถŒํ•œ ์Šน์ธ
  4. ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
  5. ๋กœ๊ทธ์ธ ์™„๋ฃŒ!

4. ๋กœ๊น… ๊ธฐ๋Šฅ

์ž๋™ ๋กœ๊น…

  • ๋ชจ๋“  ์ฟผ๋ฆฌ๊ฐ€ ์ž๋™์œผ๋กœ query_logs ํ…Œ์ด๋ธ”์— ์ €์žฅ๋จ
  • ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž๋งŒ ๋ณธ์ธ์˜ ๋กœ๊ทธ ํ™•์ธ ๊ฐ€๋Šฅ

๋กœ๊ทธ ์กฐํšŒ

curl http://localhost:3001/api/logs

ํ†ต๊ณ„ ์กฐํšŒ

curl http://localhost:3001/api/stats

5. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์กฐ

users ํ…Œ์ด๋ธ”

  • id: ์‚ฌ์šฉ์ž ID
  • google_id: ๊ตฌ๊ธ€ ID (๊ณ ์œ )
  • email: ์ด๋ฉ”์ผ
  • name: ์ด๋ฆ„
  • profile_picture: ํ”„๋กœํ•„ ์‚ฌ์ง„ URL
  • created_at: ๊ฐ€์ž…์ผ
  • last_login: ๋งˆ์ง€๋ง‰ ๋กœ๊ทธ์ธ

query_logs ํ…Œ์ด๋ธ”

  • id: ๋กœ๊ทธ ID
  • user_id: ์‚ฌ์šฉ์ž ID
  • query_text: ์‹คํ–‰ํ•œ ์ฟผ๋ฆฌ
  • execution_time: ์‹คํ–‰ ์‹œ๊ฐ„ (ms)
  • row_count: ๋ฐ˜ํ™˜๋œ ํ–‰ ์ˆ˜
  • success: ์„ฑ๊ณต ์—ฌ๋ถ€
  • error_message: ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ (์‹คํŒจ ์‹œ)
  • created_at: ์‹คํ–‰ ์‹œ๊ฐ

6. API ์—”๋“œํฌ์ธํŠธ

์ธ์ฆ

  • GET /auth/google - ๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ์‹œ์ž‘
  • GET /auth/google/callback - ๋กœ๊ทธ์ธ ์ฝœ๋ฐฑ
  • GET /auth/logout - ๋กœ๊ทธ์•„์›ƒ
  • GET /api/user - ํ˜„์žฌ ์‚ฌ์šฉ์ž ์ •๋ณด

๋กœ๊น…

  • GET /api/logs?limit=50 - ์ฟผ๋ฆฌ ํžˆ์Šคํ† ๋ฆฌ (์ตœ๊ทผ 50๊ฐœ)
  • GET /api/stats - ์‚ฌ์šฉ์ž ํ†ต๊ณ„

์ฟผ๋ฆฌ (๊ธฐ์กด)

  • POST /api/query - ์ฟผ๋ฆฌ ์‹คํ–‰ (์ž๋™ ๋กœ๊น…)
  • GET /api/schema - ํ…Œ์ด๋ธ” ์Šคํ‚ค๋งˆ
  • GET /api/sample/:column - ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ