@@ -8,8 +8,8 @@ const fs = require('fs');
88const httpProxy = require ( 'http-proxy' ) ;
99
1010// Account server configuration - switch between local and production
11- const ACCOUNT_SERVER = 'https://account.phcode.dev' ; // Production
12- // const ACCOUNT_SERVER = 'http://localhost:5000'; // Local development
11+ let accountServer = 'https://account.phcode.dev' ; // Production
12+ // Set to local development server if --localAccount flag is provided
1313
1414// Default configuration
1515let config = {
@@ -45,6 +45,8 @@ function parseArgs() {
4545 config . silent = true ;
4646 } else if ( arg === '--log-ip' ) {
4747 config . logIp = true ;
48+ } else if ( arg === '--localAccount' ) {
49+ accountServer = 'http://localhost:5000' ;
4850 } else if ( ! arg . startsWith ( '-' ) ) {
4951 config . root = path . resolve ( arg ) ;
5052 }
@@ -74,7 +76,7 @@ proxy.on('proxyReq', (proxyReq, req) => {
7476 const originalOrigin = req . headers . origin ;
7577
7678 // Set target host
77- const accountHost = new URL ( ACCOUNT_SERVER ) . hostname ;
79+ const accountHost = new URL ( accountServer ) . hostname ;
7880 proxyReq . setHeader ( 'Host' , accountHost ) ;
7981
8082 // Transform referer from localhost:8000 to phcode.dev
@@ -262,12 +264,12 @@ const server = http.createServer((req, res) => {
262264 req . url = targetPath + ( parsedUrl . search || '' ) ;
263265
264266 if ( ! config . silent ) {
265- console . log ( `[PROXY] ${ req . method } ${ originalUrl } -> ${ ACCOUNT_SERVER } ${ req . url } ` ) ;
267+ console . log ( `[PROXY] ${ req . method } ${ originalUrl } -> ${ accountServer } ${ req . url } ` ) ;
266268 }
267269
268270 // Proxy the request
269271 proxy . web ( req , res , {
270- target : ACCOUNT_SERVER ,
272+ target : accountServer ,
271273 changeOrigin : true ,
272274 secure : true
273275 } ) ;
@@ -313,7 +315,7 @@ server.listen(config.port, config.host, () => {
313315 console . log ( `Available on:` ) ;
314316 console . log ( ` http://${ config . host === '0.0.0.0' ? 'localhost' : config . host } :${ config . port } ` ) ;
315317 console . log ( `Proxy routes:` ) ;
316- console . log ( ` /proxy/accounts/* -> ${ ACCOUNT_SERVER } /*` ) ;
318+ console . log ( ` /proxy/accounts/* -> ${ accountServer } /*` ) ;
317319 console . log ( 'Hit CTRL-C to stop the server' ) ;
318320 }
319321} ) ;
0 commit comments