File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1+ import type { LogType } from 'vite' ;
2+
13import svg from '@poppanator/sveltekit-svg' ;
24import { sveltekit } from '@sveltejs/kit/vite' ;
35import { playwright } from '@vitest/browser-playwright' ;
6+ import { createLogger } from 'vite' ;
47import { defineConfig } from 'vitest/config' ;
58
69const API_HOST = process . env . API_HOST ?? 'https://crates.io' ;
710
11+ const proxyLogger = createLogger ( 'info' , { prefix : '[proxy]' } ) ;
12+
813export default defineConfig ( {
914 plugins : [ sveltekit ( ) , svg ( ) ] ,
1015
1116 server : {
1217 proxy : {
13- '/api' : API_HOST ,
18+ '/api' : {
19+ target : API_HOST ,
20+ changeOrigin : true ,
21+ configure : proxy => {
22+ proxy . on ( 'proxyRes' , ( proxyRes , req ) => {
23+ let level : LogType = 'info' ;
24+ if ( ( proxyRes . statusCode ?? 0 ) >= 500 ) {
25+ level = 'error' ;
26+ } else if ( ( proxyRes . statusCode ?? 0 ) >= 400 ) {
27+ level = 'warn' ;
28+ }
29+
30+ const msg = `${ req . method } ${ req . url } → ${ proxyRes . statusCode } ${ proxyRes . statusMessage } ` ;
31+ proxyLogger [ level ] ( msg , { timestamp : true } ) ;
32+ } ) ;
33+ } ,
34+ } ,
1435 } ,
1536 } ,
1637
You can’t perform that action at this time.
0 commit comments