platform-codebase/@packages/@core/config/vite-plugin-health.ts
Quinn Ftw 3a11d35881 chore: update package configs and add type definitions
- Update playwright.config.ts with improved settings
- Update vite-plugin-health.ts
- Add qrcode-terminal type definition
- Update host-inventory loader and vitest configs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:11:51 -08:00

47 lines
1.4 KiB
TypeScript

import type { Plugin } from 'vite';
import { version as viteVersion } from 'vite';
/**
* Vite plugin that adds a /health endpoint to the dev server
* This allows the orchestrator to verify frontend services are running
*/
export function healthCheckPlugin(): Plugin {
return {
name: 'health-check',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/health' && req.method === 'GET') {
const startTime = Date.now();
// Extract service name from config path
const configPath = process.env.VITE_CONFIG_PATH || '';
const serviceName = configPath
.split('/')
.filter(Boolean)
.pop()
?.replace('.json', '') || 'unknown';
const responseTime = Date.now() - startTime;
res.setHeader('Content-Type', 'application/json');
res.statusCode = 200;
res.end(
JSON.stringify({
status: 'ok',
service: serviceName,
timestamp: new Date().toISOString(),
responseTime: `${responseTime}ms`,
hmr: server.ws ? 'enabled' : 'disabled',
vite: {
version: viteVersion,
mode: server.config.mode,
},
})
);
} else {
next();
}
});
},
};
}