Skip to content

Commit f1b05ef

Browse files
committed
fixed proxy config handling
1 parent 9cb9a82 commit f1b05ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

bin/http-server

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,18 @@ function listen(port) {
204204

205205
if (proxyConfig) {
206206
try {
207-
proxyConfig = JSON.parse(fs.readFileSync(proxyConfig));
207+
if (fs.existsSync(proxyConfig)) {
208+
proxyConfig = fs.readFileSync(proxyConfig, 'utf8');
209+
}
210+
if (typeof proxyConfig === 'string') {
211+
proxyConfig = JSON.parse(proxyConfig);
212+
}
213+
if (typeof proxyConfig !== 'object') {
214+
throw new Error('Invalid proxy config');
215+
}
208216
}
209217
catch (err) {
210-
logger.info(chalk.red('Error: Invalid proxy config file'));
218+
logger.info(chalk.red('Error: Invalid proxy config or file'));
211219
process.exit(1);
212220
}
213221
// Proxy file overrides cli config

0 commit comments

Comments
 (0)