forked from emarock/proxy-pac-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-env.js
More file actions
55 lines (50 loc) · 1.58 KB
/
command-env.js
File metadata and controls
55 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const meta = require('./package')
const debug = require('debug')(meta.name + ':command-env')
const request = require('request')
const os = require('os')
exports.command = 'env [options]'
exports.describe = 'Display the commands to set up the environment'
exports.builder = {
'address': {},
'port': {},
'reset': {}
}
exports.handler = async (argv) => {
try {
if (argv.reset) {
console.log('unset HTTP_PROXY HTTPS_PROXY NO_PROXY')
console.log('unset http_proxy https_proxy no_proxy')
console.log('# Run this command to configure your shell:')
console.log('# eval $(' + argv['$0'] + ' env -r)')
} else {
const url = `http://${argv.address}:${argv.port}/status`
request({
url: url,
json: true
}, (err, res, body) => {
if (err) {
console.error('Proxy is not running')
console.error(err)
process.exit(1)
} else if (Math.floor(res.statusCode / 100) != 2) {
console.error('Proxy is not running')
console.error(res.statusMessage)
process.exit(1)
}
const proxy = `http://${body.host}:${body.port}`
const noproxy = `localhost,127.0.0.1,${os.hostname()},${body.host}`
console.log(`export HTTP_PROXY=${proxy}`)
console.log(`export HTTPS_PROXY=${proxy}`)
console.log(`export NO_PROXY=${noproxy}`)
console.log(`export http_proxy=${proxy}`)
console.log(`export https_proxy=${proxy}`)
console.log(`export no_proxy=${noproxy}`)
console.log('# Run this command to configure your shell:')
console.log('# eval $(' + argv['$0'] + ' env)')
})
}
} catch (err) {
console.error('Proxy is not running')
console.error(err)
}
}