cff52b4b9e
- Travel dates: TopBar chip + popover (outbound/return/travellers); sent to Grok prompt; itinerary.needsTravelDates drives a nudge banner; cache and prefetch ledger invalidate when dates change - Sea crossings: CrossingOption schema (Eurotunnel, DFDS, P&O, Brittany, Stena Line); CrossingSwapBlock under tunnel/ferry/crossing stops with trip-impact deltas and Book links; prompt requires 3-5 real options for every UK ↔ mainland route; picking a crossing triggers silent re-plan - Tesla in-car polish: UA + heuristic detection sets <html class="incar">; CSS overrides kill backdrop-filter, scale fonts, enforce 44px tap targets, disable hover flicker; geolocation + reverse geocode + crosshair button inside the From input; up/down arrow reorder buttons replace touch-broken HTML5 drag-and-drop - Tesla Fleet API stub: /.well-known/appspecific/com.tesla.3p.public-key.pem served from TESLA_FLEET_PUBLIC_KEY for partner domain verification; OAuth callback + vehicle_data stub return 503 until partner approval - Dockerfile + .dockerignore for Dokku deployment; server now serves client/dist in production
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import 'dotenv/config';
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import helmet from 'helmet';
|
|
import cookieParser from 'cookie-parser';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { existsSync } from 'node:fs';
|
|
import { env } from './config/env.js';
|
|
import { logger } from './lib/logger.js';
|
|
import chatRoutes from './routes/chat.js';
|
|
import tripsRoutes from './routes/trips.js';
|
|
import teslaRoutes from './routes/tesla.js';
|
|
import { createOptionalAuth } from './lib/auth.js';
|
|
|
|
const app = express();
|
|
|
|
app.use(helmet({ contentSecurityPolicy: false }));
|
|
app.use(cors({ origin: env.appUrl, credentials: true }));
|
|
app.use(express.json({ limit: '2mb' }));
|
|
app.use(cookieParser());
|
|
|
|
app.use((req, _res, next) => {
|
|
if (req.url !== '/health') logger.info({ method: req.method, url: req.url }, 'request');
|
|
next();
|
|
});
|
|
|
|
app.get('/health', (_req, res) => {
|
|
res.json({ status: 'ok', service: 'tesla-roadtrip', time: new Date().toISOString() });
|
|
});
|
|
|
|
const auth = createOptionalAuth();
|
|
if (auth) {
|
|
app.use(auth.middleware());
|
|
app.use(auth.routes());
|
|
logger.info('Auth middleware mounted (AUTH_SECRET present)');
|
|
} else {
|
|
logger.info('Auth disabled — set AUTH_SECRET to enable user accounts');
|
|
}
|
|
|
|
// Tesla integration: serves the partner public key + OAuth callback. Mounted
|
|
// at the app root because Tesla's well-known path is fixed.
|
|
app.use(teslaRoutes);
|
|
|
|
app.use('/api', chatRoutes);
|
|
app.use('/api/trips', tripsRoutes);
|
|
|
|
// ─── Static client (production only) ─────────────────────────────────────────
|
|
// In dev, Vite serves the client on :5173. In production (Dokku), the built
|
|
// client lands in client/dist via `npm run build` and we serve it from here.
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const clientDist = path.resolve(__dirname, '../../client/dist');
|
|
if (existsSync(clientDist)) {
|
|
app.use(express.static(clientDist, { index: false, maxAge: '1h' }));
|
|
app.get('*', (req, res, next) => {
|
|
// Don't shadow API or well-known paths.
|
|
if (req.path.startsWith('/api') || req.path.startsWith('/.well-known')) return next();
|
|
res.sendFile(path.join(clientDist, 'index.html'));
|
|
});
|
|
logger.info({ clientDist }, 'Serving built client');
|
|
} else {
|
|
logger.info('No client/dist found — relying on Vite dev server');
|
|
}
|
|
|
|
app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
|
logger.error({ err }, 'Unhandled error');
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
});
|
|
|
|
app.listen(env.port, () => {
|
|
logger.info(`Tesla Roadtrip server running on port ${env.port}`);
|
|
});
|