mise a jour structure visuel BO
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Backend configuration for contact form emails.
|
||||
# Copy this file to `.env` and fill in your SMTP details.
|
||||
#
|
||||
|
||||
# SMTP server host (e.g. smtp.gmail.com, smtp.mailgun.org, etc.)
|
||||
SMTP_HOST=mail.sebvtl.com
|
||||
|
||||
# SMTP port (465 for SSL, 587 for TLS)
|
||||
SMTP_PORT=465
|
||||
|
||||
# Use "true" if your provider requires SSL (port 465)
|
||||
# Otherwise leave to "false" for TLS (port 587)
|
||||
SMTP_SECURE=true
|
||||
|
||||
# SMTP credentials
|
||||
SMTP_USER=contact@sebvtl.com
|
||||
SMTP_PASS=Lightwave9.0**
|
||||
|
||||
# Optional: override the recipient (defaults to sebastien@octopusdesign.fr)
|
||||
CONTACT_RECIPIENT=sebastien@octopusdesign.fr
|
||||
|
||||
# Optional: override the "from" address visible in the email client
|
||||
CONTACT_FROM=no-reply@octopusdesign.fr
|
||||
|
||||
# Optional: add extra allowed origins for CORS (comma separated)
|
||||
# Example: CORS_ALLOWED_ORIGINS=https://preprod.octopusdesign.fr,https://admin.octopusdesign.fr
|
||||
CORS_ALLOWED_ORIGINS=
|
||||
@@ -0,0 +1,123 @@
|
||||
import express from "express";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const buildTransporterConfig = () => {
|
||||
const host = process.env.SMTP_HOST;
|
||||
const port = Number(process.env.SMTP_PORT || 587);
|
||||
const secure =
|
||||
typeof process.env.SMTP_SECURE === "string"
|
||||
? process.env.SMTP_SECURE === "true"
|
||||
: port === 465;
|
||||
|
||||
const user = process.env.SMTP_USER;
|
||||
const pass = process.env.SMTP_PASS;
|
||||
|
||||
const baseConfig = {
|
||||
host,
|
||||
port,
|
||||
secure,
|
||||
};
|
||||
|
||||
if (user && pass) {
|
||||
baseConfig.auth = { user, pass };
|
||||
}
|
||||
|
||||
return baseConfig;
|
||||
};
|
||||
|
||||
router.post("/contact", async (req, res) => {
|
||||
const { name, email, subject, message, consent } = req.body || {};
|
||||
|
||||
console.info("📨 Requête contact reçue", {
|
||||
name,
|
||||
email,
|
||||
subject,
|
||||
consent,
|
||||
});
|
||||
|
||||
if (!name || !email || !subject || !message) {
|
||||
return res.status(400).json({
|
||||
message:
|
||||
"Merci de compléter tous les champs requis avant d'envoyer votre message.",
|
||||
});
|
||||
}
|
||||
|
||||
const recipient =
|
||||
process.env.CONTACT_RECIPIENT || "sebastien@octopusdesign.fr";
|
||||
const fromAddress =
|
||||
process.env.CONTACT_FROM ||
|
||||
process.env.SMTP_FROM ||
|
||||
process.env.SMTP_USER ||
|
||||
"no-reply@octopusdesign.fr";
|
||||
|
||||
try {
|
||||
const transporter = nodemailer.createTransport(buildTransporterConfig());
|
||||
|
||||
const mailSubject = subject.trim()
|
||||
? `[Site Octopus Design] ${subject.trim()}`
|
||||
: "Nouveau message depuis le site Octopus Design";
|
||||
|
||||
const consentLabel = consent ? "✅ Consentement donné" : "❌ Consentement non fourni";
|
||||
|
||||
const textBody = `
|
||||
Nom : ${name}
|
||||
E-mail : ${email}
|
||||
Consentement : ${consentLabel}
|
||||
|
||||
Message :
|
||||
${message}
|
||||
`;
|
||||
|
||||
const htmlBody = `
|
||||
<p><strong>Nom :</strong> ${name}</p>
|
||||
<p><strong>E-mail :</strong> ${email}</p>
|
||||
<p><strong>Consentement :</strong> ${consentLabel}</p>
|
||||
<p><strong>Message :</strong></p>
|
||||
<p>${message.replace(/\n/g, "<br />")}</p>
|
||||
`;
|
||||
|
||||
// Vérifie la connexion SMTP avant d'essayer d'envoyer
|
||||
await transporter.verify();
|
||||
|
||||
const mailOptions = {
|
||||
from: `"Octopus Design" <${fromAddress}>`,
|
||||
to: recipient,
|
||||
replyTo: email,
|
||||
subject: mailSubject,
|
||||
text: textBody,
|
||||
html: htmlBody,
|
||||
};
|
||||
|
||||
await transporter.sendMail(mailOptions);
|
||||
|
||||
console.info(
|
||||
"✅ Email de contact envoyé avec succès",
|
||||
JSON.stringify(
|
||||
{
|
||||
to: recipient,
|
||||
replyTo: email,
|
||||
subject: mailSubject,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
message: "Votre message a bien été envoyé. Merci pour votre confiance !",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"❌ Erreur lors de l'envoi du mail de contact :",
|
||||
error?.stack || error?.message || error
|
||||
);
|
||||
return res.status(500).json({
|
||||
message:
|
||||
"Impossible d'envoyer votre message pour le moment. Merci de réessayer plus tard.",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,17 +1,37 @@
|
||||
import express from "express";
|
||||
import dotenv from "dotenv";
|
||||
import cloudinaryRoute from "./cloudinaryRoute.js";
|
||||
import cors from "cors";
|
||||
import cloudinaryRoute from "./cloudinaryRoute.js";
|
||||
import contactRoute from "./contactRoute.js";
|
||||
|
||||
dotenv.config();
|
||||
const app = express();
|
||||
|
||||
app.use(cors({
|
||||
// origin: "https://octopusdesign.fr"
|
||||
origin: ["https://octopusdesign.fr", "http://localhost:3000"]
|
||||
}));
|
||||
const allowedOrigins = (process.env.CORS_ALLOWED_ORIGINS || "")
|
||||
.split(",")
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const defaultOrigins = [
|
||||
"https://octopusdesign.fr",
|
||||
"https://www.octopusdesign.fr",
|
||||
"https://preprod.octopusdesign.fr",
|
||||
"http://localhost:3000",
|
||||
"http://localhost:5173",
|
||||
];
|
||||
|
||||
const origins = [...new Set([...defaultOrigins, ...allowedOrigins])];
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin: origins,
|
||||
})
|
||||
);
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use("/api", cloudinaryRoute);
|
||||
app.use("/api", contactRoute);
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
app.listen(PORT, () => {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"axios": "^1.6.7",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2"
|
||||
"express": "^4.18.2",
|
||||
"nodemailer": "^6.9.11"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user