Ports the single-file MedCsFiz page — the medical centre that already runs physiotherapy and wants the existing room to earn more — to the same architecture as the fitness and hotel landings: Vite + React 19 + TypeScript + Tailwind v4 on the client, Express 5 for the API, zod schema shared between the two. The original stays in legacy/index.html as the visual reference. Its 4 MB of inlined CSS, JS and base64 images become 12 asset files (664 KB) plus a bundle loaded on demand; the two 1.5 MB / 750 KB device PNGs are recompressed to webp. The page is split into 18 components with all copy moved to src/data/content.ts. Leads reuse the fitness amoCRM integration: contact lookup by phone in every Russian spelling, deal in the first stage of pipeline 10980758, account fields matched automatically with the rest written to a note. Rate limit, honeypot and a localStorage fallback so a lead survives the CRM being down. Endpoint is /api/leads/medical-centers-existing-physio; Vite runs on 5173 and the API on 3000. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { config as loadEnv } from 'dotenv'
|
|
|
|
loadEnv()
|
|
|
|
function optional(name: string): string | undefined {
|
|
const value = process.env[name]?.trim()
|
|
return value ? value : undefined
|
|
}
|
|
|
|
function optionalNumber(name: string): number | undefined {
|
|
const raw = optional(name)
|
|
if (raw === undefined) return undefined
|
|
const value = Number(raw)
|
|
if (!Number.isFinite(value)) throw new Error(`${name} must be a number, got "${raw}"`)
|
|
return value
|
|
}
|
|
|
|
/**
|
|
* amoCRM settings. Deliberately not throwing when they are missing: the site
|
|
* must still boot and serve pages without a CRM connection — only the lead
|
|
* endpoint degrades, and it says so explicitly.
|
|
*/
|
|
export interface AmoConfig {
|
|
baseUrl: string
|
|
token: string
|
|
pipelineId: number
|
|
responsibleUserId?: number
|
|
tags: string[]
|
|
}
|
|
|
|
export function readAmoConfig(): AmoConfig | null {
|
|
const subdomain = optional('AMO_SUBDOMAIN')
|
|
const token = optional('AMO_LONG_LIVED_TOKEN')
|
|
if (!subdomain || !token) return null
|
|
|
|
// Accepts "exotherapy", "exotherapy.amocrm.ru", or a full URL (an explicit
|
|
// scheme is kept as-is, which is what local mocks and self-hosted setups need).
|
|
const host = subdomain.replace(/\/+$/, '')
|
|
const baseUrl = /^https?:\/\//.test(host)
|
|
? host
|
|
: `https://${host.includes('.') ? host : `${host}.${optional('AMO_DOMAIN') ?? 'amocrm.ru'}`}`
|
|
|
|
return {
|
|
baseUrl,
|
|
token,
|
|
pipelineId: optionalNumber('AMO_PIPELINE_ID') ?? 10980758,
|
|
responsibleUserId: optionalNumber('AMO_RESPONSIBLE_USER_ID'),
|
|
tags: (optional('AMO_LEAD_TAGS') ?? '')
|
|
.split(',')
|
|
.map((t) => t.trim())
|
|
.filter(Boolean),
|
|
}
|
|
}
|
|
|
|
export const serverConfig = {
|
|
port: optionalNumber('PORT') ?? 3000,
|
|
isProduction: process.env.NODE_ENV === 'production',
|
|
}
|