最近开发了一个小应用,会涉及到部分“不存在”的内容。
服务器在国外,所以不存在这个问题,但是本地调试的话会获取不到内容。
研究了下 Node.js 进程中使用 SS 代理的方式,总结出以下的代码(基于axios):
// change host / port / protocol to your real values
const axiosOptions: AxiosRequestConfig = {}
const httpsAgent = new SocksProxyAgent({
host: '127.0.0.1',
port: 1086,
protocol: 'socks5:',
rejectUnauthorized: false
})
axiosOptions.httpAgent = httpsAgent
axiosOptions.httpsAgent = httpsAgent
axiosOptions.proxy = false
process.env.NODE_TLS_REJECT_UNAUTHORIZED = null // dangerous, do not use in production.
export const rest = axios.create(axiosOptions)
// rest.get('https://google.com')