diff --git a/code/websites/pokedex.online/deploy.sh b/code/websites/pokedex.online/deploy.sh index cec0e5a..77c7a23 100755 --- a/code/websites/pokedex.online/deploy.sh +++ b/code/websites/pokedex.online/deploy.sh @@ -209,6 +209,41 @@ run_tests() { # Build ############################################################################### +prepare_env_for_build() { + # Create/update .env.local with correct Discord redirect URI for the target + local env_file="$PROJECT_ROOT/.env.local" + local redirect_uri + + # Determine correct redirect URI based on target and ports + case "$TARGET" in + local) + # For Docker, use the frontend port + redirect_uri="http://localhost:${PORT}/oauth/callback" + ;; + internal|external) + # For dev server, use default Vite port + redirect_uri="http://localhost:5173/oauth/callback" + ;; + *) + redirect_uri="http://localhost:5173/oauth/callback" + ;; + esac + + log_info "Preparing environment for ${TARGET} deployment..." + log_info "Discord redirect URI: ${redirect_uri}" + + # Create/update .env.local with Discord credentials + cat > "$env_file" << EOF +# Generated by deploy.sh for ${TARGET} deployment +# These variables are embedded into the frontend bundle at build time + +VITE_DISCORD_CLIENT_ID=1466544972059775223 +VITE_DISCORD_REDIRECT_URI=${redirect_uri} +EOF + + log_info ".env.local created with correct redirect URI" +} + build_application() { if [ "$SKIP_BUILD" = true ]; then log_warning "Skipping build (--skip-build flag set)" @@ -224,6 +259,9 @@ build_application() { log_step "🔨 Building Application" + # Prepare environment before building + prepare_env_for_build + log_info "Building frontend..." npm run build:frontend || { log_error "Frontend build failed"