@@ -8,8 +8,8 @@ const fs = require('fs');
8
8
const httpProxy = require ( 'http-proxy' ) ;
9
9
10
10
// 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
13
13
14
14
// Default configuration
15
15
let config = {
@@ -45,6 +45,8 @@ function parseArgs() {
45
45
config . silent = true ;
46
46
} else if ( arg === '--log-ip' ) {
47
47
config . logIp = true ;
48
+ } else if ( arg === '--localAccount' ) {
49
+ accountServer = 'http://localhost:5000' ;
48
50
} else if ( ! arg . startsWith ( '-' ) ) {
49
51
config . root = path . resolve ( arg ) ;
50
52
}
@@ -74,7 +76,7 @@ proxy.on('proxyReq', (proxyReq, req) => {
74
76
const originalOrigin = req . headers . origin ;
75
77
76
78
// Set target host
77
- const accountHost = new URL ( ACCOUNT_SERVER ) . hostname ;
79
+ const accountHost = new URL ( accountServer ) . hostname ;
78
80
proxyReq . setHeader ( 'Host' , accountHost ) ;
79
81
80
82
// Transform referer from localhost:8000 to phcode.dev
@@ -262,12 +264,12 @@ const server = http.createServer((req, res) => {
262
264
req . url = targetPath + ( parsedUrl . search || '' ) ;
263
265
264
266
if ( ! config . silent ) {
265
- console . log ( `[PROXY] ${ req . method } ${ originalUrl } -> ${ ACCOUNT_SERVER } ${ req . url } ` ) ;
267
+ console . log ( `[PROXY] ${ req . method } ${ originalUrl } -> ${ accountServer } ${ req . url } ` ) ;
266
268
}
267
269
268
270
// Proxy the request
269
271
proxy . web ( req , res , {
270
- target : ACCOUNT_SERVER ,
272
+ target : accountServer ,
271
273
changeOrigin : true ,
272
274
secure : true
273
275
} ) ;
@@ -313,7 +315,7 @@ server.listen(config.port, config.host, () => {
313
315
console . log ( `Available on:` ) ;
314
316
console . log ( ` http://${ config . host === '0.0.0.0' ? 'localhost' : config . host } :${ config . port } ` ) ;
315
317
console . log ( `Proxy routes:` ) ;
316
- console . log ( ` /proxy/accounts/* -> ${ ACCOUNT_SERVER } /*` ) ;
318
+ console . log ( ` /proxy/accounts/* -> ${ accountServer } /*` ) ;
317
319
console . log ( 'Hit CTRL-C to stop the server' ) ;
318
320
}
319
321
} ) ;
0 commit comments