Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求海外服务器(使用SSR(ShadowSocks),代理请求,绕过墙,解决504问题) #312

Closed
ly525 opened this issue Aug 5, 2019 · 0 comments

Comments

@ly525
Copy link
Owner

ly525 commented Aug 5, 2019

请求海外服务器(使用SSR(ShadowSocks),代理请求,绕过墙,解决504问题)

使用 proxy agent 解决访问 node proxy 代理失败的问题([HPM] Error occurred while trying to proxy request)

问题

本地开发时候,希望能够直连测试服务器 API,但海外服务器因为业务原因,在海外。导致访问速度非常慢,甚至经常超时,导致开发效率非常低

于是尝试需求如何在代理 API 的时候,能够利用小飞机做代理增强,增强访问海外服务器的速度,提升开发体验

最终终于在 http-proxy-middleware 的文档里面找到了一些线索,结合小飞机做实验,最终发现确实可行

更进一步(TODO):可以深入看看 http-proxy-middleware proxy-agent node 网络代理相关的知识和这几个库的更多使用场景!

经常性报错(没有找到方案时候的情况)

 I  Your application is running here: http://0.0.0.0:9527
[HPM] Error occurred while trying to proxy request /v1/api/queryReport from 0.0.0.0:1234 to http://www.abc.com/ (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

http://blog.epoos.com/2018/05/21/proxy-error/

create-react-app

// dependencies: proxy-agent、http-proxy-middleware
// reference: https://medium.com/@Pavan_/set-up-proxy-to-work-with-multiple-apis-in-create-react-app-be595a713eb2

// location: project/src/setupProxy.js(if not exist, create it)

const ProxyAgent = require('proxy-agent')
const proxy = require('http-proxy-middleware')

const ProxyAgent = require('proxy-agent')
const proxy = require('http-proxy-middleware')

module.exports = function (app) {
    app.use(proxy('/api', {
        agent: new ProxyAgent('socks5://127.0.0.1:1086'),
        target: 'http://abc.com/',
        changeOrigin: true,
    }))
}

vue cli2

// location: project/config/index.js
// dependencies: proxy-agent、

const ProxyAgent = require('proxy-agent')

proxyTable: {
      '/api': {
        agent: new ProxyAgent('socks5://127.0.0.1:1086'),
        target: 'http://abc.com/',
        changeOrigin: true,
   }  
},

vue cli3

// location: project/vue.config.js
// dependencies: proxy-agent

const ProxyAgent = require('proxy-agent')

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        agent: new ProxyAgent('socks5://127.0.0.1:1086'),
        target: 'http://api.com',
        changeOrigin: true,
      }
    }
  },
}

image

@ly525 ly525 changed the title 312. 使用 proxy agent 解决访问 proxy 代理失败的问题 312. 使用 proxy agent 解决访问 node proxy 代理失败的问题 Aug 5, 2019
@ly525 ly525 changed the title 312. 使用 proxy agent 解决访问 node proxy 代理失败的问题 312. 使用 proxy agent 解决访问 node proxy 代理失败的问题([HPM] Error occurred while trying to proxy request) Aug 29, 2019
@ly525 ly525 added the 工程化 label Oct 5, 2019
@ly525 ly525 changed the title 312. 使用 proxy agent 解决访问 node proxy 代理失败的问题([HPM] Error occurred while trying to proxy request) 请求海外服务器(使用SSR(ShadowSocks),代理请求,绕过墙,解决504问题) Mar 26, 2020
Repository owner locked and limited conversation to collaborators Jan 23, 2024
@ly525 ly525 converted this issue into discussion #638 Jan 23, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Development

No branches or pull requests

1 participant