Fix health check timing and improve admin login
- Increase health check wait times in Gitea Actions workflow - Add additional main page accessibility check with longer timeout - Remove basic auth middleware to use custom admin login only - Custom admin login at /manage route provides better UX than browser basic auth This should resolve the 'Main page is not accessible' issue and provide a nicer admin login experience.
This commit is contained in:
@@ -142,7 +142,7 @@ jobs:
|
|||||||
- name: Wait for containers to be ready
|
- name: Wait for containers to be ready
|
||||||
run: |
|
run: |
|
||||||
echo "⏳ Waiting for containers to be ready..."
|
echo "⏳ Waiting for containers to be ready..."
|
||||||
sleep 30
|
sleep 45
|
||||||
|
|
||||||
# Check if all containers are running
|
# Check if all containers are running
|
||||||
echo "📊 Checking container status..."
|
echo "📊 Checking container status..."
|
||||||
@@ -150,12 +150,23 @@ jobs:
|
|||||||
|
|
||||||
# Wait for application container to be healthy
|
# Wait for application container to be healthy
|
||||||
echo "🏥 Waiting for application container to be healthy..."
|
echo "🏥 Waiting for application container to be healthy..."
|
||||||
for i in {1..30}; do
|
for i in {1..60}; do
|
||||||
if docker exec portfolio-app curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
if docker exec portfolio-app curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||||
echo "✅ Application container is healthy!"
|
echo "✅ Application container is healthy!"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "⏳ Waiting for application container... ($i/30)"
|
echo "⏳ Waiting for application container... ($i/60)"
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
# Additional wait for main page to be accessible
|
||||||
|
echo "🌐 Waiting for main page to be accessible..."
|
||||||
|
for i in {1..30}; do
|
||||||
|
if curl -f http://localhost:3000/ > /dev/null 2>&1; then
|
||||||
|
echo "✅ Main page is accessible!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "⏳ Waiting for main page... ($i/30)"
|
||||||
sleep 3
|
sleep 3
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -2,41 +2,6 @@ import { NextResponse } from 'next/server';
|
|||||||
import type { NextRequest } from 'next/server';
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
export function middleware(request: NextRequest) {
|
export function middleware(request: NextRequest) {
|
||||||
// Protect admin routes with Basic Auth (legacy routes)
|
|
||||||
if (request.nextUrl.pathname.startsWith('/admin') ||
|
|
||||||
request.nextUrl.pathname.startsWith('/dashboard') ||
|
|
||||||
request.nextUrl.pathname.startsWith('/control')) {
|
|
||||||
|
|
||||||
const authHeader = request.headers.get('authorization');
|
|
||||||
const basicAuth = process.env.ADMIN_BASIC_AUTH;
|
|
||||||
|
|
||||||
if (!basicAuth) {
|
|
||||||
return new NextResponse('Admin access not configured', { status: 500 });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!authHeader || !authHeader.startsWith('Basic ')) {
|
|
||||||
return new NextResponse('Authentication required', {
|
|
||||||
status: 401,
|
|
||||||
headers: {
|
|
||||||
'WWW-Authenticate': 'Basic realm="Admin Area"',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const credentials = authHeader.split(' ')[1];
|
|
||||||
const [username, password] = Buffer.from(credentials, 'base64').toString().split(':');
|
|
||||||
const [expectedUsername, expectedPassword] = basicAuth.split(':');
|
|
||||||
|
|
||||||
if (username !== expectedUsername || password !== expectedPassword) {
|
|
||||||
return new NextResponse('Invalid credentials', {
|
|
||||||
status: 401,
|
|
||||||
headers: {
|
|
||||||
'WWW-Authenticate': 'Basic realm="Admin Area"',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// For /manage and /editor routes, let them handle their own session-based auth
|
// For /manage and /editor routes, let them handle their own session-based auth
|
||||||
// These routes will redirect to login if not authenticated
|
// These routes will redirect to login if not authenticated
|
||||||
if (request.nextUrl.pathname.startsWith('/manage') ||
|
if (request.nextUrl.pathname.startsWith('/manage') ||
|
||||||
|
|||||||
Reference in New Issue
Block a user