最近开发了一个小应用,会涉及到部分“不存在”的内容。

    服务器在国外,所以不存在这个问题,但是本地调试的话会获取不到内容。

    研究了下 Node.js 进程中使用 SS 代理的方式,总结出以下的代码(基于axios):

    1. // change host / port / protocol to your real values
    2. const axiosOptions: AxiosRequestConfig = {}
    3. const httpsAgent = new SocksProxyAgent({
    4. host: '127.0.0.1',
    5. port: 1086,
    6. protocol: 'socks5:',
    7. rejectUnauthorized: false
    8. })
    9. axiosOptions.httpAgent = httpsAgent
    10. axiosOptions.httpsAgent = httpsAgent
    11. axiosOptions.proxy = false
    12. process.env.NODE_TLS_REJECT_UNAUTHORIZED = null // dangerous, do not use in production.
    13. export const rest = axios.create(axiosOptions)
    14. // rest.get('https://google.com')