Compare commits
7 Commits
fix/cloudf
...
feat/issue
| Author | SHA1 | Date | |
|---|---|---|---|
| ddab32d3ef | |||
| f33d29fe7b | |||
| 9017c933f4 | |||
| 856e20c19c | |||
| 6ca0256bf7 | |||
| 70759d6c1c | |||
| 5ab329adbf |
13
.env.example
Normal file
13
.env.example
Normal file
@ -0,0 +1,13 @@
|
||||
PUBLIC_CONTACT_FORM_ACTION_URL=/api/contact
|
||||
PUBLIC_CONTACT_FORM_SUCCESS_REDIRECT=http://localhost:4321/#contatti
|
||||
PUBLIC_CONTACT_FORM_MAILTO=
|
||||
PUBLIC_CONTACT_TURNSTILE_SITE_KEY=
|
||||
|
||||
CONTACT_FORM_MODE=dev
|
||||
CONTACT_FORM_RESEND_API_KEY=
|
||||
CONTACT_FORM_FROM_EMAIL=no-reply@nexstudio.com
|
||||
CONTACT_FORM_TO_EMAIL=info@nexstudio.com
|
||||
CONTACT_FORM_TO_EMAIL_INFO=info@nexstudio.com
|
||||
CONTACT_FORM_TO_EMAIL_PRIVACY=
|
||||
CONTACT_FORM_TO_EMAIL_CAREERS=
|
||||
CONTACT_TURNSTILE_SECRET_KEY=
|
||||
137
README.md
137
README.md
@ -1,52 +1,123 @@
|
||||
# Astro Starter Kit: Minimal
|
||||
# NexStudio Website Runbook
|
||||
|
||||
```sh
|
||||
npm create astro@latest -- --template minimal
|
||||
```
|
||||
Sito istituzionale NexStudio basato su Astro, con deploy su Cloudflare e form contatti protetto da Turnstile.
|
||||
|
||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||
## Obiettivo del repository
|
||||
|
||||
## 🚀 Project Structure
|
||||
- Presentazione aziendale e servizi (homepage e pagine legali).
|
||||
- Entry point unico per richieste commerciali e supporto.
|
||||
- Base pronta per contenuti multilingua IT/EN/TH.
|
||||
- Pipeline di deploy stabile su Cloudflare.
|
||||
|
||||
Inside of your Astro project, you'll see the following folders and files:
|
||||
## Stack tecnico
|
||||
|
||||
```text
|
||||
/
|
||||
├── public/
|
||||
├── src/
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
- Astro + Tailwind CSS
|
||||
- Adapter Cloudflare (`@astrojs/cloudflare`)
|
||||
- Sitemap (`@astrojs/sitemap`)
|
||||
- Form backend su endpoint `/api/contact`
|
||||
- Turnstile + Resend per anti-spam e invio email
|
||||
|
||||
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
|
||||
## Struttura essenziale
|
||||
|
||||
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
|
||||
- `src/pages/`: pagine pubbliche e route API (`src/pages/api/contact.ts`)
|
||||
- `src/components/`: componenti UI condivisi
|
||||
- `src/data/`: contenuti testuali e configurazioni pagine
|
||||
- `public/`: asset statici (loghi, immagini, robots)
|
||||
- `.env.example`: variabili locali di riferimento
|
||||
|
||||
Any static assets, like images, can be placed in the `public/` directory.
|
||||
## Prerequisiti
|
||||
|
||||
## 🧞 Commands
|
||||
- Node.js 20+
|
||||
- npm 10+
|
||||
- Account Cloudflare (Pages/Workers + Turnstile)
|
||||
- Account Resend (API key + sender verificato)
|
||||
|
||||
All commands are run from the root of the project, from a terminal:
|
||||
## Avvio locale
|
||||
|
||||
| Command | Action |
|
||||
| :------------------------ | :----------------------------------------------- |
|
||||
| `npm install` | Installs dependencies |
|
||||
| `npm run dev` | Starts local dev server at `localhost:4321` |
|
||||
| `npm run build` | Build your production site to `./dist/` |
|
||||
| `npm run preview` | Preview your build locally, before deploying |
|
||||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
|
||||
| `npm run astro -- --help` | Get help using the Astro CLI |
|
||||
1. Installazione dipendenze:
|
||||
- `npm install`
|
||||
2. Copia variabili di ambiente:
|
||||
- copia `.env.example` in `.env`
|
||||
3. Avvio sviluppo:
|
||||
- `npm run dev`
|
||||
4. Se Vite resta in cache incoerente:
|
||||
- `npm run dev:fresh`
|
||||
|
||||
## 👀 Want to learn more?
|
||||
## Comandi utili
|
||||
|
||||
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
|
||||
- `npm run dev`: sviluppo locale
|
||||
- `npm run dev:fresh`: reset cache `.vite` e `.astro` + avvio dev server
|
||||
- `npm run build`: build produzione
|
||||
- `npm run preview`: preview locale della build
|
||||
- `npm run deploy:cf`: build + deploy con wrangler su output Astro
|
||||
|
||||
## Cloudflare deploy notes
|
||||
## Configurazione contatti
|
||||
|
||||
If you deploy with Wrangler in CI/Cloudflare, build first and deploy using Astro's generated Worker config:
|
||||
Variabili pubbliche (frontend):
|
||||
|
||||
- `PUBLIC_CONTACT_FORM_ACTION_URL` (default consigliato: `/api/contact`)
|
||||
- `PUBLIC_CONTACT_FORM_SUCCESS_REDIRECT` (URL assoluto della pagina post-submit)
|
||||
- `PUBLIC_CONTACT_FORM_MAILTO` (fallback se action URL non disponibile)
|
||||
- `PUBLIC_CONTACT_TURNSTILE_SITE_KEY`
|
||||
|
||||
Variabili server (Cloudflare/local):
|
||||
|
||||
- `CONTACT_FORM_MODE` (`dev` oppure `live`)
|
||||
- `CONTACT_FORM_RESEND_API_KEY`
|
||||
- `CONTACT_FORM_FROM_EMAIL` (consigliato: `no-reply@nexstudio.ai`)
|
||||
- `CONTACT_FORM_TO_EMAIL` (default destinatario, es. `info@nexstudio.ai`)
|
||||
- `CONTACT_FORM_TO_EMAIL_INFO` (opzionale, override esplicito per area "info")
|
||||
- `CONTACT_FORM_TO_EMAIL_PRIVACY`
|
||||
- `CONTACT_FORM_TO_EMAIL_CAREERS`
|
||||
- `CONTACT_TURNSTILE_SECRET_KEY`
|
||||
|
||||
Comportamento:
|
||||
|
||||
- `dev`: accetta submit e scrive payload nei log (senza invio reale)
|
||||
- `live`: valida Turnstile e invia email via Resend
|
||||
|
||||
Routing pubblico consigliato (portale vetrina):
|
||||
|
||||
- `info`: informazioni generali/commerciali
|
||||
- `privacy`: richieste privacy e diritti interessato
|
||||
- `careers`: candidature e collaborazioni
|
||||
|
||||
Indirizzi consigliati portale:
|
||||
|
||||
- `info@nexstudio.ai`
|
||||
- `privacy@nexstudio.ai`
|
||||
- `careers@nexstudio.ai`
|
||||
- `no-reply@nexstudio.ai` (solo invio comunicazioni/newsletter, non destinazione inbound)
|
||||
|
||||
## Deploy Cloudflare
|
||||
|
||||
Impostazioni consigliate:
|
||||
|
||||
- Build command: `npm run build`
|
||||
- Deploy command: `npm run deploy:cf`
|
||||
|
||||
This avoids entrypoint errors like `@astrojs/cloudflare/entrypoints/server` not found.
|
||||
Questa configurazione evita errori tipo:
|
||||
`The entry-point file at "@astrojs/cloudflare/entrypoints/server" was not found.`
|
||||
|
||||
## Dominio e sicurezza
|
||||
|
||||
- Dominio ufficiale: `https://nexstudio.ai`
|
||||
- Hostname Turnstile da mantenere allineati:
|
||||
- `nexstudio.ai`
|
||||
- `www.nexstudio.ai` (se usato)
|
||||
- `localhost` (test locale)
|
||||
- Accesso pre-go-live gestito con Cloudflare Zero Trust Access
|
||||
|
||||
## Stato operativo attuale
|
||||
|
||||
- Issue #1 (contact form live): implementata
|
||||
- Issue #2 (anti-spam Turnstile): implementata
|
||||
- Issue #3 (SEO base): implementata (sitemap, robots, canonical/OG/Twitter)
|
||||
- Issue #4: in avanzamento (contenuti non placeholder)
|
||||
- Issue #5: da completare (localizzazione reale IT/EN/TH)
|
||||
|
||||
## Note operative
|
||||
|
||||
- Per modifiche non minori usare branch dedicato (`feat/*`, `fix/*`) e merge su `main` dopo verifica.
|
||||
- Evitare commit su `main` per attivita complesse.
|
||||
- Rigenerare eventuali API key esposte e aggiornare subito i secret su Cloudflare.
|
||||
|
||||
@ -4,6 +4,7 @@ import { defineConfig } from 'astro/config';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import cloudflare from '@astrojs/cloudflare';
|
||||
import alpinejs from '@astrojs/alpinejs';
|
||||
import sitemap from '@astrojs/sitemap';
|
||||
|
||||
/**
|
||||
* Mitiga race su richieste SSR parallele durante l’ottimizzazione dipendenze
|
||||
@ -34,7 +35,7 @@ function viteSsrOptimizeIgnoreOutdated() {
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
/** Usato da Astro per URL assoluti (es. sitemap). Imposta il dominio di produzione. */
|
||||
// site: 'https://www.tuodominio.com',
|
||||
site: 'https://nexstudio.ai',
|
||||
|
||||
output: 'server', // per il deployment su Cloudflare Pages
|
||||
|
||||
@ -43,7 +44,7 @@ export default defineConfig({
|
||||
},
|
||||
|
||||
adapter: cloudflare(),
|
||||
integrations: [alpinejs()],
|
||||
integrations: [alpinejs(), sitemap()],
|
||||
i18n: {
|
||||
defaultLocale: 'it',
|
||||
locales: ['it', 'en', 'th'],
|
||||
|
||||
67
package-lock.json
generated
67
package-lock.json
generated
@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@astrojs/alpinejs": "^0.5.0",
|
||||
"@astrojs/cloudflare": "^13.1.10",
|
||||
"@astrojs/sitemap": "^3.7.2",
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"@types/alpinejs": "^3.13.11",
|
||||
"alpinejs": "^3.15.11",
|
||||
@ -105,6 +106,17 @@
|
||||
"node": ">=22.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@astrojs/sitemap": {
|
||||
"version": "3.7.2",
|
||||
"resolved": "https://registry.npmjs.org/@astrojs/sitemap/-/sitemap-3.7.2.tgz",
|
||||
"integrity": "sha512-PqkzkcZTb5ICiyIR8VoKbIAP/laNRXi5tw616N1Ckk+40oNB8Can1AzVV56lrbC5GKSZFCyJYUVYqVivMisvpA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"sitemap": "^9.0.0",
|
||||
"stream-replace-string": "^2.0.0",
|
||||
"zod": "^4.3.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@astrojs/telemetry": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.3.1.tgz",
|
||||
@ -2095,6 +2107,24 @@
|
||||
"@types/unist": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.12.2.tgz",
|
||||
"integrity": "sha512-A1sre26ke7HDIuY/M23nd9gfB+nrmhtYyMINbjI1zHJxYteKR6qSMX56FsmjMcDb3SMcjJg5BiRRgOCC/yBD0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/sax": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz",
|
||||
"integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/unist": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz",
|
||||
@ -2156,6 +2186,12 @@
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/arg": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz",
|
||||
"integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
@ -4992,6 +5028,25 @@
|
||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/sitemap": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sitemap/-/sitemap-9.0.1.tgz",
|
||||
"integrity": "sha512-S6hzjGJSG3d6if0YoF5kTyeRJvia6FSTBroE5fQ0bu1QNxyJqhhinfUsXi9fH3MgtXODWvwo2BDyQSnhPQ88uQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "^24.9.2",
|
||||
"@types/sax": "^1.2.1",
|
||||
"arg": "^5.0.0",
|
||||
"sax": "^1.4.1"
|
||||
},
|
||||
"bin": {
|
||||
"sitemap": "dist/esm/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.5",
|
||||
"npm": ">=10.8.2"
|
||||
}
|
||||
},
|
||||
"node_modules/smol-toml": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.6.1.tgz",
|
||||
@ -5023,6 +5078,12 @@
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/stream-replace-string": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/stream-replace-string/-/stream-replace-string-2.0.0.tgz",
|
||||
"integrity": "sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/stringify-entities": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
|
||||
@ -5207,6 +5268,12 @@
|
||||
"node": ">=20.18.1"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.16.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/unenv": {
|
||||
"version": "2.0.0-rc.24",
|
||||
"resolved": "https://registry.npmjs.org/unenv/-/unenv-2.0.0-rc.24.tgz",
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
"dependencies": {
|
||||
"@astrojs/alpinejs": "^0.5.0",
|
||||
"@astrojs/cloudflare": "^13.1.10",
|
||||
"@astrojs/sitemap": "^3.7.2",
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"@types/alpinejs": "^3.13.11",
|
||||
"alpinejs": "^3.15.11",
|
||||
|
||||
4
public/robots.txt
Normal file
4
public/robots.txt
Normal file
@ -0,0 +1,4 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
|
||||
Sitemap: https://nexstudio.ai/sitemap-index.xml
|
||||
@ -11,6 +11,7 @@ const model = {
|
||||
fieldName: cf.fieldName,
|
||||
fieldCompany: cf.fieldCompany,
|
||||
fieldCountry: cf.fieldCountry,
|
||||
fieldDepartment: cf.fieldDepartment,
|
||||
fieldEmail: cf.fieldEmail,
|
||||
fieldMessage: cf.fieldMessage,
|
||||
};
|
||||
@ -161,6 +162,20 @@ const fieldClass =
|
||||
class={fieldClass}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-nx-muted" for="nx-cf-department">
|
||||
{cf.departmentLabel}
|
||||
</label>
|
||||
<select
|
||||
id="nx-cf-department"
|
||||
name={cf.fieldDepartment}
|
||||
class={fieldClass}
|
||||
>
|
||||
{cf.departmentOptions.map((opt) => (
|
||||
<option value={opt.value}>{opt.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-nx-muted" for="nx-cf-msg">
|
||||
{cf.messageLabel}
|
||||
|
||||
@ -1,4 +1,10 @@
|
||||
/** Call-to-action (blocco contatti / chiusura pagina) */
|
||||
const env = import.meta.env;
|
||||
const contactActionUrl = (env.PUBLIC_CONTACT_FORM_ACTION_URL ?? '/api/contact').trim();
|
||||
const contactSuccessRedirect = (env.PUBLIC_CONTACT_FORM_SUCCESS_REDIRECT ?? '').trim();
|
||||
const contactMailto = (env.PUBLIC_CONTACT_FORM_MAILTO ?? '').trim();
|
||||
const contactTurnstileSiteKey = (env.PUBLIC_CONTACT_TURNSTILE_SITE_KEY ?? '').trim();
|
||||
|
||||
export const cta = {
|
||||
/** Riga sezione (stesso ruolo di FAQ, Stack, …) */
|
||||
eyebrow: 'Contatti',
|
||||
@ -24,26 +30,33 @@ export const cta = {
|
||||
nameLabel: 'Nome',
|
||||
companyLabel: 'Azienda (opzionale)',
|
||||
countryLabel: 'Paese',
|
||||
departmentLabel: 'Area',
|
||||
emailLabel: 'Email',
|
||||
messageLabel: 'Scrivi qui il tuo messaggio',
|
||||
submitLabel: 'Invia messaggio',
|
||||
/** Formspree: `https://formspree.io/f/xxxx` — vuoto = prova `mailto` */
|
||||
actionUrl: '',
|
||||
/** Formspree: redirect dopo invio (`_next`) — URL **assoluta** in produzione */
|
||||
successRedirect: '',
|
||||
/** Formspree: `https://formspree.io/f/xxxx` — valorizzato via `PUBLIC_CONTACT_FORM_ACTION_URL` */
|
||||
actionUrl: contactActionUrl,
|
||||
/** Formspree `_next` — URL assoluta in produzione (`PUBLIC_CONTACT_FORM_SUCCESS_REDIRECT`) */
|
||||
successRedirect: contactSuccessRedirect,
|
||||
/**
|
||||
* Cloudflare Turnstile (anti-spam): inserisci qui la site key pubblica.
|
||||
* Se vuota, il CAPTCHA non viene mostrato.
|
||||
*/
|
||||
turnstileSiteKey: '',
|
||||
turnstileSiteKey: contactTurnstileSiteKey,
|
||||
/** Formspree `_subject` e oggetto mailto */
|
||||
notifySubject: 'Richiesta contatto — sito NexStudio',
|
||||
/** Se `actionUrl` è vuoto: email per `mailto:` (es. `info@tuodominio.com`) */
|
||||
mailto: '',
|
||||
/** Fallback se `actionUrl` e' vuoto (`PUBLIC_CONTACT_FORM_MAILTO`) */
|
||||
mailto: contactMailto,
|
||||
fieldName: 'name',
|
||||
fieldCompany: 'company',
|
||||
fieldCountry: 'country',
|
||||
fieldDepartment: 'department',
|
||||
fieldEmail: 'email',
|
||||
fieldMessage: 'message',
|
||||
departmentOptions: [
|
||||
{ value: 'info', label: 'Informazioni generali e commerciali' },
|
||||
{ value: 'privacy', label: 'Privacy' },
|
||||
{ value: 'careers', label: 'Careers / Collaborazioni' },
|
||||
],
|
||||
},
|
||||
} as const;
|
||||
|
||||
@ -15,6 +15,7 @@ const {
|
||||
const pathname = Astro.url.pathname;
|
||||
const localeMatch = pathname.match(/^\/(en|th)(\/|$)/);
|
||||
const htmlLang = localeMatch?.[1] ?? 'it';
|
||||
const canonicalUrl = Astro.url.toString();
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@ -23,7 +24,16 @@ const htmlLang = localeMatch?.[1] ?? 'it';
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content={description} />
|
||||
<link rel="canonical" href={canonicalUrl} />
|
||||
<meta name="theme-color" content="#030712" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="NexStudio" />
|
||||
<meta property="og:title" content={title} />
|
||||
<meta property="og:description" content={description} />
|
||||
<meta property="og:url" content={canonicalUrl} />
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:title" content={title} />
|
||||
<meta name="twitter:description" content={description} />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
|
||||
163
src/pages/api/contact.ts
Normal file
163
src/pages/api/contact.ts
Normal file
@ -0,0 +1,163 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
type RuntimeEnv = Record<string, unknown>;
|
||||
|
||||
function getRuntimeEnv(locals: unknown): RuntimeEnv {
|
||||
if (
|
||||
locals &&
|
||||
typeof locals === 'object' &&
|
||||
'runtime' in locals &&
|
||||
locals.runtime &&
|
||||
typeof locals.runtime === 'object' &&
|
||||
'env' in locals.runtime &&
|
||||
locals.runtime.env &&
|
||||
typeof locals.runtime.env === 'object'
|
||||
) {
|
||||
return locals.runtime.env as RuntimeEnv;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function readEnv(name: string, runtimeEnv: RuntimeEnv): string {
|
||||
const runtimeValue = runtimeEnv[name];
|
||||
if (typeof runtimeValue === 'string' && runtimeValue.trim().length > 0) {
|
||||
return runtimeValue.trim();
|
||||
}
|
||||
const staticValue = import.meta.env[name];
|
||||
return typeof staticValue === 'string' ? staticValue.trim() : '';
|
||||
}
|
||||
|
||||
function sanitizeRedirect(candidate: string, requestUrl: URL): string {
|
||||
if (!candidate) return '';
|
||||
try {
|
||||
const u = new URL(candidate, requestUrl);
|
||||
return u.toString();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function required(value: FormDataEntryValue | null): string {
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
}
|
||||
|
||||
async function verifyTurnstile(token: string, secret: string, ip?: string | null): Promise<boolean> {
|
||||
const body = new URLSearchParams();
|
||||
body.set('secret', secret);
|
||||
body.set('response', token);
|
||||
if (ip) body.set('remoteip', ip);
|
||||
|
||||
const response = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
if (!response.ok) return false;
|
||||
const payload = (await response.json()) as { success?: boolean };
|
||||
return payload.success === true;
|
||||
}
|
||||
|
||||
async function sendWithResend(apiKey: string, fromEmail: string, toEmail: string, subject: string, text: string) {
|
||||
const response = await fetch('https://api.resend.com/emails', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
from: fromEmail,
|
||||
to: [toEmail],
|
||||
subject,
|
||||
text,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const detail = await response.text();
|
||||
throw new Error(`Resend error ${response.status}: ${detail}`);
|
||||
}
|
||||
}
|
||||
|
||||
function resolveDepartmentRecipient(runtimeEnv: RuntimeEnv, defaultRecipient: string, department: string): string {
|
||||
const normalized = department.trim().toLowerCase();
|
||||
const map: Record<string, string> = {
|
||||
info: readEnv('CONTACT_FORM_TO_EMAIL_INFO', runtimeEnv) || defaultRecipient,
|
||||
privacy: readEnv('CONTACT_FORM_TO_EMAIL_PRIVACY', runtimeEnv),
|
||||
careers: readEnv('CONTACT_FORM_TO_EMAIL_CAREERS', runtimeEnv),
|
||||
};
|
||||
return map[normalized] || defaultRecipient;
|
||||
}
|
||||
|
||||
export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
const runtimeEnv = getRuntimeEnv(locals);
|
||||
const mode = readEnv('CONTACT_FORM_MODE', runtimeEnv).toLowerCase() || 'dev';
|
||||
const resendApiKey = readEnv('CONTACT_FORM_RESEND_API_KEY', runtimeEnv);
|
||||
const fromEmail = readEnv('CONTACT_FORM_FROM_EMAIL', runtimeEnv);
|
||||
const toEmail = readEnv('CONTACT_FORM_TO_EMAIL', runtimeEnv);
|
||||
const turnstileSecret = readEnv('CONTACT_TURNSTILE_SECRET_KEY', runtimeEnv);
|
||||
|
||||
const form = await request.formData();
|
||||
const redirectTarget =
|
||||
sanitizeRedirect(required(form.get('_next')), url) ||
|
||||
sanitizeRedirect(readEnv('PUBLIC_CONTACT_FORM_SUCCESS_REDIRECT', runtimeEnv), url) ||
|
||||
sanitizeRedirect(request.headers.get('referer') ?? '/', url) ||
|
||||
'/';
|
||||
|
||||
const name = required(form.get('name'));
|
||||
const company = required(form.get('company'));
|
||||
const email = required(form.get('email'));
|
||||
const country = required(form.get('country'));
|
||||
const department = required(form.get('department')) || 'info';
|
||||
const message = required(form.get('message'));
|
||||
|
||||
if (!name || !email || !country || !message) {
|
||||
return new Response('Missing required contact fields.', { status: 400 });
|
||||
}
|
||||
|
||||
const turnstileToken = required(form.get('cf-turnstile-response'));
|
||||
if (turnstileSecret) {
|
||||
const isHuman = await verifyTurnstile(
|
||||
turnstileToken,
|
||||
turnstileSecret,
|
||||
request.headers.get('CF-Connecting-IP'),
|
||||
);
|
||||
if (!isHuman) {
|
||||
return new Response('Turnstile verification failed.', { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
const subject = required(form.get('_subject')) || 'Richiesta contatto - sito NexStudio';
|
||||
const text = [
|
||||
`Nome: ${name}`,
|
||||
company ? `Azienda: ${company}` : '',
|
||||
`Email: ${email}`,
|
||||
`Paese: ${country}`,
|
||||
`Reparto: ${department}`,
|
||||
'',
|
||||
message,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
|
||||
if (mode === 'live') {
|
||||
if (!resendApiKey || !fromEmail || !toEmail) {
|
||||
return new Response('Live mode requires CONTACT_FORM_RESEND_API_KEY, CONTACT_FORM_FROM_EMAIL and CONTACT_FORM_TO_EMAIL.', {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
const destination = resolveDepartmentRecipient(runtimeEnv, toEmail, department);
|
||||
await sendWithResend(resendApiKey, fromEmail, destination, subject, text);
|
||||
} else {
|
||||
console.info('[contact:dev] Contact payload received', {
|
||||
name,
|
||||
company,
|
||||
email,
|
||||
country,
|
||||
department,
|
||||
subject,
|
||||
});
|
||||
}
|
||||
|
||||
return Response.redirect(redirectTarget, 303);
|
||||
};
|
||||
@ -6,13 +6,32 @@ import SubpageLayout from '../layouts/SubpageLayout.astro';
|
||||
title="Novità — NexStudio"
|
||||
description="Novità, release e articoli da NexStudio."
|
||||
heading="Novità"
|
||||
lead="Hub comunicazioni: collegate qui il vostro blog CMS, oppure elencate manualmente le notizie."
|
||||
lead="Aggiornamenti ufficiali su piattaforma, compliance, infrastruttura e contenuti editoriali."
|
||||
>
|
||||
<p>
|
||||
Quando avrete contenuti da pubblicare (release di prodotto, note di
|
||||
conformità, eventi), potete sostituire questa pagina con una raccolta
|
||||
articoli Astro, un redirect verso Medium/Substack, o un headless CMS.
|
||||
<p class="rounded-xl border border-emerald-500/30 bg-emerald-500/10 px-4 py-3 text-emerald-100">
|
||||
Stato editoriale: canale attivo. Le prossime pubblicazioni verranno aggiornate su questa pagina con frequenza periodica.
|
||||
</p>
|
||||
|
||||
<h2>Programma editoriale</h2>
|
||||
<ul>
|
||||
<li><strong>Release tecniche:</strong> aggiornamenti su funzionalita, integrazioni e miglioramenti di stabilita.</li>
|
||||
<li><strong>Compliance:</strong> novita su policy, sicurezza applicativa e adempimenti normativi.</li>
|
||||
<li><strong>Case e risultati:</strong> note operative su adozione, scalabilita e impatti di business.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Canali di distribuzione</h2>
|
||||
<ul>
|
||||
<li>Questa pagina resta il punto di riferimento ufficiale per annunci e changelog sintetici.</li>
|
||||
<li>La newsletter verra attivata appena disponibile il canale comunicazioni dedicato.</li>
|
||||
<li>I contenuti long-form potranno essere pubblicati anche su canali esterni, con rimando qui.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Archivio</h2>
|
||||
<p class="text-nx-muted">Nessuna news pubblicata per il momento.</p>
|
||||
<p class="text-nx-muted">
|
||||
In questa fase il sito e in pre-lancio operativo. Il primo blocco di news verra pubblicato con il go-live ufficiale.
|
||||
</p>
|
||||
<p>
|
||||
Per richieste stampa, partnership o approfondimenti tecnici e possibile usare il form nella sezione
|
||||
<a href="/#contatti" class="text-sky-300 hover:text-sky-200">Contatti</a>.
|
||||
</p>
|
||||
</SubpageLayout>
|
||||
|
||||
@ -8,6 +8,7 @@ interface ContactFormCfg {
|
||||
fieldName: string;
|
||||
fieldCompany: string;
|
||||
fieldCountry: string;
|
||||
fieldDepartment: string;
|
||||
fieldEmail: string;
|
||||
fieldMessage: string;
|
||||
}
|
||||
@ -25,6 +26,7 @@ function readCfg(): ContactFormCfg {
|
||||
fieldName: 'name',
|
||||
fieldCompany: 'company',
|
||||
fieldCountry: 'country',
|
||||
fieldDepartment: 'department',
|
||||
fieldEmail: 'email',
|
||||
fieldMessage: 'message',
|
||||
};
|
||||
@ -67,12 +69,13 @@ function bind(): void {
|
||||
const company = String(fd.get(cfg.fieldCompany) ?? '').trim();
|
||||
const email = String(fd.get(cfg.fieldEmail) ?? '').trim();
|
||||
const country = String(fd.get(cfg.fieldCountry) ?? '').trim();
|
||||
const department = String(fd.get(cfg.fieldDepartment) ?? '').trim();
|
||||
const message = String(fd.get(cfg.fieldMessage) ?? '').trim();
|
||||
if (cfg.mailto) {
|
||||
const subject = encodeURIComponent(cfg.notifySubject || 'Contatto sito');
|
||||
const companyLine = company ? `\nAzienda: ${company}` : '';
|
||||
const body = encodeURIComponent(
|
||||
`Nome: ${name}${companyLine}\nEmail: ${email}\nPaese: ${country}\n\n${message}`,
|
||||
`Nome: ${name}${companyLine}\nEmail: ${email}\nPaese: ${country}\nReparto: ${department || 'general'}\n\n${message}`,
|
||||
);
|
||||
window.location.href = `mailto:${cfg.mailto}?subject=${subject}&body=${body}`;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user