Add Next.js API rewrite proxy
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
- Added rewrites() in next.config.js to proxy /api/v1/* to backend - Works regardless of whether Nginx is in front or external proxy goes directly to Next.js - Disabled standalone output for non-Docker deployments
This commit is contained in:
@ -1,7 +1,21 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
output: 'standalone', // Required for Docker deployment
|
||||
// output: 'standalone', // Only needed for Docker deployment
|
||||
|
||||
// Proxy API requests to backend
|
||||
// This ensures /api/v1/* works regardless of how the server is accessed
|
||||
async rewrites() {
|
||||
// Determine backend URL based on environment
|
||||
const backendUrl = process.env.BACKEND_URL || 'http://127.0.0.1:8000'
|
||||
|
||||
return [
|
||||
{
|
||||
source: '/api/v1/:path*',
|
||||
destination: `${backendUrl}/api/v1/:path*`,
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = nextConfig
|
||||
|
||||
Reference in New Issue
Block a user