-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
58 lines (56 loc) · 1.71 KB
/
vite.config.ts
File metadata and controls
58 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { defineConfig, type Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { logger } from './api/logger';
/**
* Vite dev plugin: receives client-side log entries via POST /__client-log
* and writes them to the server-side log file + stdout.
*/
function clientLogPlugin(): Plugin {
return {
name: 'client-log-relay',
configureServer(server) {
server.middlewares.use('/__client-log', (req, res) => {
if (req.method !== 'POST') {
res.statusCode = 405;
res.end();
return;
}
let body = '';
req.on('data', (chunk: Buffer) => { body += chunk.toString(); });
req.on('end', () => {
try {
const { level, message, athleteId, data } = JSON.parse(body);
const prefix = '[CLIENT]';
if (level === 'error') {
logger.error(`${prefix} ${message}`, athleteId, data);
} else if (level === 'warn') {
logger.warn(`${prefix} ${message}`, athleteId, data);
} else {
logger.info(`${prefix} ${message}`, athleteId, data);
}
} catch {
logger.error('[CLIENT] Failed to parse client log payload');
}
res.statusCode = 204;
res.end();
});
});
},
};
}
export default defineConfig({
base: './',
envPrefix: ['VITE_', 'INTERVALS_'],
plugins: [react(), tailwindcss(), clientLogPlugin()],
server: {
proxy: {
'/intervals': {
target: 'https://intervals.icu',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/intervals/, ''),
},
'/api': 'http://localhost:3000',
},
},
});