feat(api): enhance backend API configuration and routing for multi-domain support

- Updated `next.config.mjs` to implement host-based routing for two domains, allowing seamless API proxying to the appropriate backend based on the host.
- Refactored backend API base URL logic in `config.ts` to dynamically determine the correct URL based on the deployment environment, supporting both production and test setups.
- Modified `CreateCompany` form to validate website input with a regex pattern and changed input type to text for better user experience.
This commit is contained in:
AmirReza Jamali
2026-06-01 11:34:42 +03:30
parent eb41f9b7b2
commit f0902d7536
3 changed files with 56 additions and 12 deletions
+24 -1
View File
@@ -34,10 +34,33 @@ const nextConfig = {
],
},
async rewrites() {
// The same build is deployed to two domains, each with its own backend:
// - test: opplenz.com -> https://admin.opplenz.com/admin/v1
// - production: opplens.com -> https://admin.opplens.com/admin/v1
// Routing is host-based so neither deploy needs a custom env. A
// `BACKEND_API_BASE_URL` env var (if set) overrides both — handy for local
// dev pointing at e.g. http://localhost:8080/admin/v1.
const override = process.env.BACKEND_API_BASE_URL;
if (override) {
return [
{
source: "/api/proxy/:path*",
destination: `${override}/:path*`,
},
];
}
return [
// Production: any opplens.com host (apex or subdomain like www.).
{
source: "/api/proxy/:path*",
destination: `https://admin.opplenz.com/admin/v1/:path*`,
has: [{ type: "host", value: "(.*\\.)?opplens\\.com" }],
destination: "https://admin.opplens.com/admin/v1/:path*",
},
// Default (test opplenz.com + local dev).
{
source: "/api/proxy/:path*",
destination: "https://admin.opplenz.com/admin/v1/:path*",
},
];
},