1- import { createServer } from 'http' ;
1+ import { createServer } from 'http' ;
22import os from 'os' ;
3- import { start } from './index.js' ;
3+ import { start } from './index.js' ;
44import * as config from './index.config.js' ;
5+ import axios from "axios" ;
56
67globalThis . catServerFactory = ( handle ) => {
78 let port = 0 ;
89 const server = createServer ( ( req , res ) => {
910 handle ( req , res ) ;
1011 } ) ;
1112
12- server . on ( 'listening' , ( ) => {
13+ // 自动 GET 请求逻辑
14+ async function autoRequest ( url ) {
15+ try {
16+ const response = await axios . get ( url ) ; // 替换为目标接口
17+ console . log ( `Auto-request successful: ${ response . data . message || '' } ` ) ;
18+ } catch ( error ) {
19+ console . log ( `Auto-request failed: ${ error . message } ` ) ;
20+ }
21+ }
22+
23+ server . on ( 'listening' , async ( ) => {
1324 port = server . address ( ) . port ;
1425
1526 // Get local IP addresses
@@ -22,13 +33,15 @@ globalThis.catServerFactory = (handle) => {
2233 }
2334 }
2435 }
36+ const localConfigUrl = `http://localhost:${ port } /config` ;
2537
2638 console . log ( `Server is running:` ) ;
27- console . log ( `- Local: http://localhost: ${ port } /config ` ) ;
39+ console . log ( `- Local: ${ localConfigUrl } ` ) ;
2840 if ( addresses . length > 0 ) {
2941 console . log ( `- Network: http://${ addresses [ 0 ] } :${ port } /config` ) ;
3042 }
3143 console . log ( `- Node.js version: ${ process . version } ` ) ;
44+ await autoRequest ( localConfigUrl ) ;
3245 } ) ;
3346
3447 server . on ( 'close' , ( ) => {
0 commit comments