Skip to content

Commit de2bef5

Browse files
committed
build: npm scrits to login from account.phcode.dev or localhost dev account servers
- npm run serve - uses production account server (https://account.phcode.dev) - npm run serveLocalAccount - uses local account server (http://localhost:5000
1 parent d9bd622 commit de2bef5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"_minorVersionBump": "gulp minorVersionBump",
7474
"_majorVersionBump": "gulp majorVersionBump",
7575
"serve": "node serve-proxy.js . -p 8000 -c-1",
76+
"serveLocalAccount": "node serve-proxy.js . -p 8000 -c-1 --localAccount",
7677
"_serveWithWebCacheHelp": "echo !!!Make sure to npm run release:dev/stageing/prod before testing the cache!!!",
7778
"serveWithWebCache": "npm run _releaseWebCache && npm run _serveWithWebCacheHelp && http-server ./dist -p 8000 -c-1",
7879
"serveExternal": "node serve-proxy.js . -p 8000 -a 0.0.0.0 --log-ip -c-1",
@@ -118,4 +119,4 @@
118119
"tinycolor2": "^1.4.2",
119120
"underscore": "^1.13.4"
120121
}
121-
}
122+
}

serve-proxy.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const fs = require('fs');
88
const 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
1515
let 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

Comments
 (0)