Files
carmanagement/apps/dashboard/next.config.js
T
2026-05-23 19:03:15 -04:00

56 lines
1.7 KiB
JavaScript

/** @type {import('next').NextConfig} */
const toStoragePattern = (rawUrl) => {
try {
const u = new URL(rawUrl.replace(/\/api\/v1\/?$/, ''))
return {
protocol: u.protocol.replace(':', ''),
hostname: u.hostname,
...(u.port ? { port: u.port } : {}),
pathname: '/storage/**',
}
} catch {
return null
}
}
const storagePatterns = [
process.env.API_INTERNAL_URL ?? 'http://localhost:4000',
process.env.API_URL,
process.env.NEXT_PUBLIC_API_URL,
]
.filter(Boolean)
.map(toStoragePattern)
.filter(Boolean)
.filter((p, i, arr) => arr.findIndex((q) => q.hostname === p.hostname && q.port === p.port) === i)
// When the dashboard is accessed via the marketplace proxy (localhost:3000/dashboard),
// the browser resolves _next/static chunk URLs relative to localhost:3000 — but those
// chunks only exist on the dashboard's own server (localhost:3001). DASHBOARD_ASSET_PREFIX
// makes Next.js embed absolute chunk URLs so the browser fetches them from the right port.
// Set in .env.docker.dev; unset for local/production (where no cross-port proxy is used).
const nextConfig = {
basePath: '/dashboard',
...(process.env.DASHBOARD_ASSET_PREFIX ? { assetPrefix: process.env.DASHBOARD_ASSET_PREFIX } : {}),
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'res.cloudinary.com',
},
...storagePatterns,
],
},
transpilePackages: ['@rentaldrivego/types'],
async rewrites() {
const apiOrigin = (process.env.API_INTERNAL_URL ?? process.env.API_URL ?? 'http://localhost:4000').replace(/\/api\/v1\/?$/, '')
return [
{
source: '/api/:path*',
destination: `${apiOrigin}/api/:path*`,
},
]
},
}
module.exports = nextConfig