Skip to content

Commit d056660

Browse files
committed
chore: switchable account between local and account.phcode.dev
1 parent 66a5f98 commit d056660

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

serve-proxy.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const path = require('path');
77
const fs = require('fs');
88
const httpProxy = require('http-proxy');
99

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
13+
1014
// Default configuration
1115
let config = {
1216
port: 8000,
@@ -71,7 +75,8 @@ proxy.on('proxyReq', (proxyReq, req, res) => {
7175
const originalOrigin = req.headers.origin;
7276

7377
// Set target host
74-
proxyReq.setHeader('Host', 'account.phcode.dev');
78+
const accountHost = new URL(ACCOUNT_SERVER).hostname;
79+
proxyReq.setHeader('Host', accountHost);
7580

7681
// Transform referer from localhost:8000 to phcode.dev
7782
if (originalReferer && originalReferer.includes('localhost:8000')) {
@@ -260,12 +265,12 @@ const server = http.createServer((req, res) => {
260265
req.url = targetPath + (parsedUrl.search || '');
261266

262267
if (!config.silent) {
263-
console.log(`[PROXY] ${req.method} ${originalUrl} -> https://account.phcode.dev${req.url}`);
268+
console.log(`[PROXY] ${req.method} ${originalUrl} -> ${ACCOUNT_SERVER}${req.url}`);
264269
}
265270

266271
// Proxy the request
267272
proxy.web(req, res, {
268-
target: 'https://account.phcode.dev',
273+
target: ACCOUNT_SERVER,
269274
changeOrigin: true,
270275
secure: true
271276
});
@@ -300,7 +305,7 @@ server.listen(config.port, config.host, () => {
300305
console.log(`Available on:`);
301306
console.log(` http://${config.host === '0.0.0.0' ? 'localhost' : config.host}:${config.port}`);
302307
console.log(`Proxy routes:`);
303-
console.log(` /proxy/accounts/* -> https://account.phcode.dev/*`);
308+
console.log(` /proxy/accounts/* -> ${ACCOUNT_SERVER}/*`);
304309
console.log('Hit CTRL-C to stop the server');
305310
}
306311
});

0 commit comments

Comments
 (0)