Node.js library to communicate with the shadowsocks-restful-api
npm i shadowsocks-server-api
To start a new instance:
const SsApi = require('shadowsocks-server-api')
const ssApi = new SsApi()
let server = {
host: 'Your server host',
port: 4001, //Port of shadowsocks-restful-api
token: '',
password: 'pleaseChangeThisPassword'
}
ssApi.login(server, (error, response, token) => {
// Returns response Object and an error if it contains one
console.log(token) //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NzE0NzIx...
}
})
ssApi.getPing(server, (error, response, body) => {
// Returns response Object and an error if it contains one
console.log(body) // {"pong":"pong"}
}
})
let portConfig = { // Config for shadowsocks port
port: 'port_number',
password: 'port_password',
method: 'encryption_method'
}
ssApi.addPort(server, portConfig, (error, response, body) => {
// Returns response Object and an error if it contains one
console.log(response.statusCode) // 201 Created
}
})
ssApi.getPorts(server, (error, response, body) => {
// Returns response Object and an error if it contains one
console.log(body) // [{"port":port_number, "password":"port_password","method":"encryption_method"}, ... ]
}
})
let port_to_delete = 4242
ssApi.deletePort(server, port_to_delete, (error, response, body) => {
// Returns response Object and an error if it contains one
console.log(response.statusCode) // 204 No Content
}
})
ssApi.getTrafic(server, (error, response, body) => {
// Returns response Object and an error if it contains one
console.log(body) // [{"port":port_number, "traffic": traffic_usage}, ... ]
}
})