Skip to content

Commit

Permalink
fix: 修复某些情况下代理环境变量不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Feb 15, 2020
1 parent 33d4007 commit 7deb7d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions bin/surgio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

'use strict';

process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE = '';

const SurgioCommand = require('..').SurgioCommand;

const d = new SurgioCommand();
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './utils/patch-proxy';

import { bootstrap } from 'global-agent';
import Command from 'common-bin';
import fs from 'fs';
Expand Down
22 changes: 22 additions & 0 deletions lib/utils/patch-proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// istanbul ignore file

import Debug from 'debug';

const debug = Debug('surgio:utils:patch-proxy');
const keys: ReadonlyArray<string> = [
'http_proxy',
'https_proxy',
'all_proxy',
];

process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE = '';

keys.forEach(key => {
if (key in process.env) {
const newKey = key.toUpperCase();
const value = process.env[key];

debug('Patched environment variable %s=%s', newKey, value);
process.env[newKey] = value;
}
});

0 comments on commit 7deb7d9

Please sign in to comment.