From 16c88d5fb79716cd467571331131cbc8d72e5212 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Thu, 29 Jan 2026 13:19:36 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Refactor=20OAuth=20prox?= =?UTF-8?q?y=20server=20to=20improve=20configuration=20validation,=20loggi?= =?UTF-8?q?ng,=20and=20middleware=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokedex.online/server/oauth-proxy.js | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/code/websites/pokedex.online/server/oauth-proxy.js b/code/websites/pokedex.online/server/oauth-proxy.js index 1296e00..9bca808 100644 --- a/code/websites/pokedex.online/server/oauth-proxy.js +++ b/code/websites/pokedex.online/server/oauth-proxy.js @@ -6,7 +6,7 @@ * * Usage: * Development: node server/oauth-proxy.js - * Production: Deploy as serverless function or Express app + * Production: Deploy with Docker (see docker-compose.production.yml) */ import 'dotenv/config'; @@ -14,39 +14,24 @@ import express from 'express'; import cors from 'cors'; import fetch from 'node-fetch'; import gamemasterRouter from './gamemaster-api.js'; +import { validateOrExit, getConfig } from './utils/env-validator.js'; +import logger, { requestLogger, errorLogger } from './utils/logger.js'; +import { setupGracefulShutdown, createHealthCheckMiddleware } from './utils/graceful-shutdown.js'; + +// Validate environment variables +validateOrExit(); + +// Get validated configuration +const config = getConfig(); const app = express(); -const PORT = process.env.OAUTH_PROXY_PORT || 3001; -// Environment variables (set in .env file) -const CLIENT_ID = process.env.CHALLONGE_CLIENT_ID; -const CLIENT_SECRET = process.env.CHALLONGE_CLIENT_SECRET; -const REDIRECT_URI = - process.env.CHALLONGE_REDIRECT_URI || 'http://localhost:5173/oauth/callback'; - -// Validate required environment variables -const hasChallongeAuth = CLIENT_ID && CLIENT_SECRET; -if (!hasChallongeAuth) { - console.warn('⚠️ Challonge OAuth credentials not configured:'); - console.warn(' CHALLONGE_CLIENT_ID'); - console.warn(' CHALLONGE_CLIENT_SECRET'); - console.warn('\nChallonge OAuth endpoints will be disabled.'); - console.warn('Gamemaster API will still work.\n'); -} - -app.use( - cors({ - origin: - process.env.NODE_ENV === 'production' - ? process.env.FRONTEND_URL - : [ - 'http://localhost:5173', - 'http://localhost:5174', - 'http://localhost:5175' - ] - }) -); +// Middleware +app.use(cors({ origin: config.cors.origin })); app.use(express.json()); +app.use(requestLogger); + +// Mount API routes app.use('/api/gamemaster', gamemasterRouter); /**