Compare commits
2 Commits
af33c6225d
...
15cfb314b1
| Author | SHA1 | Date | |
|---|---|---|---|
| 15cfb314b1 | |||
| a3da6192e3 |
@@ -34,12 +34,6 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 🟢 Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# LOGGING: Registry Login Phase
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
@@ -63,75 +57,6 @@ jobs:
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# LOGGING: Build Phase
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
- name: 🏗️ Build application on runner
|
||||
run: |
|
||||
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Step: Build Application on Runner ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo "📦 Installing dependencies..."
|
||||
npm ci
|
||||
|
||||
echo "🏗️ Building Next.js application..."
|
||||
npm run build
|
||||
env:
|
||||
NEXT_PUBLIC_BASE_URL: ${{ secrets.NEXT_PUBLIC_BASE_URL }}
|
||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${{ secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}
|
||||
NEXT_PUBLIC_UMAMI_SCRIPT_URL: ${{ secrets.NEXT_PUBLIC_UMAMI_SCRIPT_URL }}
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# LOGGING: Smoke Test Phase
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
- name: 🧪 Run Smoke Test
|
||||
run: |
|
||||
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Step: Smoke Test ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo "🧪 Starting local smoke test to verify build integrity..."
|
||||
|
||||
# Start the application in the background
|
||||
# We use the standalone output which is what runs in production
|
||||
export PORT=3001
|
||||
export NODE_ENV=production
|
||||
export NEXT_PUBLIC_BASE_URL="http://localhost:3001"
|
||||
|
||||
node .next/standalone/server.js &
|
||||
APP_PID=$!
|
||||
|
||||
echo "⏳ Waiting for application to start on port 3001 (PID: $APP_PID)..."
|
||||
|
||||
# Wait for health check to pass
|
||||
MAX_RETRIES=10
|
||||
RETRY_COUNT=0
|
||||
SUCCESS=false
|
||||
|
||||
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
|
||||
if curl -s http://localhost:3001/health > /dev/null; then
|
||||
SUCCESS=true
|
||||
break
|
||||
fi
|
||||
echo " • Waiting... ($((RETRY_COUNT + 1))/$MAX_RETRIES)"
|
||||
sleep 3
|
||||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||
done
|
||||
|
||||
if [ "$SUCCESS" = true ]; then
|
||||
echo "✅ Smoke test passed: Application started successfully"
|
||||
kill $APP_PID
|
||||
else
|
||||
echo "❌ Smoke test failed: Application failed to start or health check timed out"
|
||||
echo "🔍 Application Logs:"
|
||||
# Try to get some logs before killing
|
||||
kill -0 $APP_PID 2>/dev/null && sleep 2
|
||||
kill $APP_PID
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# LOGGING: Build Phase
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { getServerAppServices } from '@/lib/services/create-services.server';
|
||||
|
||||
// Create the internationalization middleware
|
||||
const intlMiddleware = createMiddleware({
|
||||
@@ -20,40 +19,20 @@ export default function middleware(request: NextRequest) {
|
||||
const referer = headers.get('referer') || 'none';
|
||||
const ip = headers.get('x-forwarded-for') || headers.get('x-real-ip') || 'unknown';
|
||||
|
||||
// Get logger service
|
||||
const services = getServerAppServices();
|
||||
const logger = services.logger.child({ middleware: 'request-logger' });
|
||||
|
||||
// Log incoming request
|
||||
logger.info(`Incoming request: method=${method} url=${url} ip=${ip} ua="${userAgent.slice(0,60)}${userAgent.length>60 ? '...' : ''}" ref="${referer.slice(0,80)}${referer.length>80 ? '...' : ''}"`);
|
||||
console.log(`Incoming request: method=${method} url=${url}`);
|
||||
|
||||
try {
|
||||
// Apply internationalization middleware
|
||||
const response = intlMiddleware(request);
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
// Log successful response
|
||||
if (response.status >= 300 && response.status < 400) {
|
||||
const location = response.headers.get('location') || 'unknown';
|
||||
logger.info(`Redirect detected: status=${response.status} location="${location.slice(0,100)}${location.length>100?'...':''}" method=${method} url=${url} duration=${duration}ms ip=${ip} ua="${userAgent.slice(0,60)}${userAgent.length>60?'...':''}" ref="${referer.slice(0,80)}${referer.length>80?'...':''}"`);
|
||||
} else {
|
||||
logger.info(`Request completed: status=${response.status} method=${method} url=${url} duration=${duration}ms ip=${ip} ua="${userAgent.slice(0,60)}${userAgent.length>60?'...':''}" ref="${referer.slice(0,80)}${referer.length>80?'...':''}"`);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
// Log error
|
||||
const errorMsg = error instanceof Error ? error.message : String(error);
|
||||
logger.error(`Request failed: method=${method} url=${url} duration=${duration}ms error="${errorMsg}" ip=${ip} ua="${userAgent.slice(0,60)}${userAgent.length>60?'...':''}" ref="${referer.slice(0,80)}${referer.length>80?'...':''}"`);
|
||||
|
||||
// Re-throw the error to let Next.js handle it
|
||||
console.error(`Request failed: method=${method} url=${url}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// Match only internationalized pathnames
|
||||
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)', '/', '/(de|en)/:path*']
|
||||
matcher: ['/((?!api|_next|_vercel|health|.*\\..*).*)', '/', '/(de|en)/:path*']
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user