feat: enhance environment configuration and CORS handling
- Added `NEXT_PUBLIC_APP_URL` and `NEXT_PUBLIC_CONTACT_EMAIL` to environment variables for frontend configuration. - Updated CORS logic to support domain-based restrictions with dynamic origin validation. - Improved frontend image hostname resolution using environment-driven URLs. - Standardized contact email usage across the application.
This commit is contained in:
@@ -33,9 +33,19 @@ import { JwtService } from "../crypto/services/jwt.service";
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// En production, on peut restreindre via une variable d'environnement (injectée par ConfigService ultérieurement ou via process.env ici pour le décorateur si besoin,
|
// En production, on peut restreindre via une variable d'environnement
|
||||||
// mais le décorateur est évalué au chargement. NestJS permet d'utiliser une fonction pour l'origine)
|
const domainName = process.env.CORS_DOMAIN_NAME;
|
||||||
callback(null, true);
|
if (!domainName || domainName === "*") {
|
||||||
|
callback(null, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allowedOrigins = domainName.split(",").map((o) => o.trim());
|
||||||
|
if (allowedOrigins.includes(origin)) {
|
||||||
|
callback(null, true);
|
||||||
|
} else {
|
||||||
|
callback(new Error("Not allowed by CORS"));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
credentials: true,
|
credentials: true,
|
||||||
methods: ["GET", "POST"],
|
methods: ["GET", "POST"],
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-https://api.memegoat.fr}
|
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-https://api.memegoat.fr}
|
||||||
|
NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL:-https://memegoat.fr}
|
||||||
|
NEXT_PUBLIC_CONTACT_EMAIL: ${MAIL_FROM:-noreply@memegoat.fr}
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const appUrl = process.env.NEXT_PUBLIC_APP_URL || "https://memegoat.fr";
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "https://api.memegoat.fr";
|
||||||
|
|
||||||
|
const getHostname = (url: string) => {
|
||||||
|
try {
|
||||||
|
return new URL(url).hostname;
|
||||||
|
} catch {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
/* config options here */
|
/* config options here */
|
||||||
reactCompiler: true,
|
reactCompiler: true,
|
||||||
@@ -7,11 +18,11 @@ const nextConfig: NextConfig = {
|
|||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
protocol: "https",
|
protocol: "https",
|
||||||
hostname: "memegoat.fr",
|
hostname: getHostname(appUrl),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
protocol: "https",
|
protocol: "https",
|
||||||
hostname: "api.memegoat.fr",
|
hostname: getHostname(apiUrl),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ export default function HelpPage() {
|
|||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
N'hésitez pas à nous contacter sur nos réseaux sociaux ou par email.
|
N'hésitez pas à nous contacter sur nos réseaux sociaux ou par email.
|
||||||
</p>
|
</p>
|
||||||
<p className="font-semibold text-primary">contact@memegoat.fr</p>
|
<p className="font-semibold text-primary">
|
||||||
|
{process.env.NEXT_PUBLIC_CONTACT_EMAIL || "contact@memegoat.fr"}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const metadata: Metadata = {
|
|||||||
openGraph: {
|
openGraph: {
|
||||||
type: "website",
|
type: "website",
|
||||||
locale: "fr_FR",
|
locale: "fr_FR",
|
||||||
url: "https://memegoat.local",
|
url: "/",
|
||||||
siteName: "MemeGoat",
|
siteName: "MemeGoat",
|
||||||
title: "MemeGoat | Partagez vos meilleurs mèmes",
|
title: "MemeGoat | Partagez vos meilleurs mèmes",
|
||||||
description: "La plateforme ultime pour les mèmes. Rejoignez le troupeau !",
|
description: "La plateforme ultime pour les mèmes. Rejoignez le troupeau !",
|
||||||
|
|||||||
Reference in New Issue
Block a user