forked from emarock/proxy-pac-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-stop.js
More file actions
37 lines (31 loc) · 926 Bytes
/
command-stop.js
File metadata and controls
37 lines (31 loc) · 926 Bytes
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
const meta = require('./package')
const debug = require('debug')(meta.name + ':command-stop')
const request = require('request')
exports.command = 'stop [options]'
exports.describe = 'Stop the proxy.pac proxy'
exports.builder = {
'address': {},
'port': {}
}
exports.handler = async (argv) => {
try {
const url = `http://${argv.address}:${argv.port}/shutdown`
request(url, (err, res, body) => {
if (err) {
console.error('Cannot stop proxy.')
console.error(err)
process.exit(1)
} else if (Math.floor(res.statusCode / 100) != 2) {
console.error('Cannot stop proxy.')
console.error(res.statusMessage)
process.exit(1)
}
console.log('Proxy successfully stopped. ')
console.log('You may reset your shell configuration ' +
'by running the `' + argv['$0'] + ' env -r` command.')
})
} catch (err) {
console.error('Cannot stop proxy.')
console.error(err)
}
}