diff --git a/.env.template b/.env.template index 31232ee..7d346f3 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,5 @@ # Configuration SMTP pour contact-backend.js +BASE_URL=http://localhost SMTP_HOST=HOST SMTP_PORT=PORT SMTP_SECURE=false diff --git a/Dockerfile b/Dockerfile index 717a9f1..94b04d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,9 @@ COPY . . RUN npm run build -EXPOSE 1313 +EXPOSE 1313 3001 -CMD ["hugo", "server", "-D", "--bind", "0.0.0.0", "--baseURL", "http://localhost:1313", "--appendPort=false"] +CMD ["sh", "-c", "BASE_URL=${BASE_URL:-http://localhost}; node contact-backend.js & hugo server -D --bind 0.0.0.0 --baseURL ${BASE_URL}:1313 --appendPort=false"] # @TODO: Ajouter une étape de build pour générer les fichiers statiques de Hugo # gunzippé et optimisé pour la production diff --git a/README.md b/README.md index 2278678..d889e29 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ docker build --no-cache -t chill-site:latest . ## Lancer le site en local avec un nom de conteneur ```bash -docker run --name chill-site-container -p 1313:1313 -d chill-site:latest +docker run --name chill-site-container -p 1313:1313 -p 3001:3001 -d chill-site:latest ``` Pour relancer après un arrêt : diff --git a/contact-backend.js b/contact-backend.js index 3ec1702..d061da0 100644 --- a/contact-backend.js +++ b/contact-backend.js @@ -37,17 +37,17 @@ app.post('/contact', upload.none(), async (req, res) => { if (req.body.website && req.body.website.trim() !== '') { return res.status(400).send('Bot détecté.'); } - const { email, sujet, message } = req.body; - if (!email || !sujet || !message) { - return res.status(400).send('Champs manquants.'); + const { email, subject, message } = req.body; + if (!email || !subject || !message) { + return res.status(400).send('Champs manquants'); } try { await transporter.sendMail({ from: process.env.SMTP_USER, to: process.env.SMTP_USER, replyTo: email, - subject: `Contact site: ${sujet}`, - text: `Email: ${email}\nSujet: ${sujet}\nMessage:\n${message}` + subject: `Contact site: ${subject}`, + text: `Email: ${email}\nSujet: ${subject}\nMessage:\n${message}` }); res.status(200).send('Message envoyé !'); } catch (err) { diff --git a/content/contact.md b/content/contact.md index 0f43853..66af27a 100644 --- a/content/contact.md +++ b/content/contact.md @@ -3,7 +3,6 @@ title: "Nous contacter" layout: "simple" contactForm: title: "Formulaire de contact" - action: "http://localhost:3001/contact" developers: title: "Échanger avec les développeurs" description: "Il existe un salon sur la messagerie Matrix, pour échanger avec les développeurs de Chill." diff --git a/hugo.toml b/hugo.toml index 48f0017..d78d0ca 100644 --- a/hugo.toml +++ b/hugo.toml @@ -45,7 +45,7 @@ pagination = { pagerSize = 6, path = "page" } # Security Configuration [security.funcs] - getenv = ['^HUGO_', '^CI$'] + getenv = ['^HUGO_', '^CI$', '^BASE_URL$'] # Required Markup Configuration diff --git a/themes/chill-theme/layouts/shortcodes/contact-form.html b/themes/chill-theme/layouts/shortcodes/contact-form.html index 8fd6914..3a821ae 100644 --- a/themes/chill-theme/layouts/shortcodes/contact-form.html +++ b/themes/chill-theme/layouts/shortcodes/contact-form.html @@ -1,9 +1,12 @@ {{ $form := .Page.Params.contactForm }} +{{ $baseURL := default "http://localhost" (getenv "BASE_URL") }} +{{ $normalizedBaseURL := strings.TrimSuffix "/" $baseURL }} +{{ $defaultContactAction := printf "%s:3001/contact" $normalizedBaseURL }}
+ action="{{ $form.action | default $defaultContactAction }}">

{{ $form.title }}

{{ range $form.fields }}