@@ -4,6 +4,29 @@ import { default as tidewavePackage } from '../../../package.json' with { type:
44
55export type LocalPortGetter = ( ) => number | undefined ;
66
7+ export interface TidewaveConfigPayload {
8+ project_name : string ;
9+ framework_type : string ;
10+ tidewave_version : string ;
11+ team : NonNullable < TidewaveConfig [ 'team' ] > | Record < string , never > ;
12+ local_port : number | undefined ;
13+ tmp_dir : string ;
14+ }
15+
16+ export function tidewaveConfig (
17+ config : TidewaveConfig ,
18+ getLocalPort ?: LocalPortGetter ,
19+ ) : TidewaveConfigPayload {
20+ return {
21+ project_name : config . projectName || 'app' ,
22+ framework_type : config . framework || 'unknown' ,
23+ tidewave_version : tidewavePackage . version ,
24+ team : config . team || { } ,
25+ local_port : getLocalPort ?.( ) ,
26+ tmp_dir : config . tmpDir || 'tmp' ,
27+ } ;
28+ }
29+
730export function createHandleConfig (
831 config : TidewaveConfig ,
932 getLocalPort ?: LocalPortGetter ,
@@ -14,19 +37,10 @@ export function createHandleConfig(
1437 next : TidewaveNext ,
1538 ) : Promise < void > {
1639 try {
17- const tidewaveConfig = {
18- project_name : config . projectName || 'app' ,
19- framework_type : config . framework || 'unknown' ,
20- tidewave_version : tidewavePackage . version ,
21- team : config . team || { } ,
22- local_port : getLocalPort ?.( ) ,
23- tmp_dir : config . tmpDir || 'tmp' ,
24- } ;
25-
2640 res . statusCode = 200 ;
2741 res . setHeader ( 'Content-Type' , 'application/json' ) ;
2842 res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
29- res . end ( JSON . stringify ( tidewaveConfig ) ) ;
43+ res . end ( JSON . stringify ( tidewaveConfig ( config , getLocalPort ) ) ) ;
3044 } catch ( err ) {
3145 console . error ( `[Tidewave] Failed to serve config: ${ err } ` ) ;
3246
0 commit comments