V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fescover

跨域请求代理有什么方案

  •  
  •   fescover · Dec 1, 2020 · 2073 views
    This topic created in 1973 days ago, the information mentioned may be changed or developed.

    react 项目 使用 axios 进行 ajax 请求 项目端口为 8000,请求 api 端口为 3000 怎样跨域请求到数据

    --append--

    如何 ip 都不同呢 比如 127.0.0.1:8000 请求 8.8.8.8:30000

    7 replies    2020-12-01 12:45:55 +08:00
    themostlazyman
        1
    themostlazyman  
       Dec 1, 2020
    cors,nginx
    fescover
        2
    fescover  
    OP
       Dec 1, 2020
    @themostlazyman 需要前端方案,后端代码改不了
    icebay
        3
    icebay  
       Dec 1, 2020
    本地架设一个 nginx 做代理
    sarices
        4
    sarices  
       Dec 1, 2020
    开发用 webapck proxytable,上线用 nginx
    zqx
        5
    zqx  
       Dec 1, 2020 via Android
    本地起一个几十行代码的 node 转发服务就可以了,Webpack 已经集成了这种服务,有个字段设置一下就行,具体看文档
    aaronlam
        6
    aaronlam  
       Dec 1, 2020
    像 jsonp,cors 都是需要后端配合,既然后端改不了。
    那就只能前端自己架个 node 或者 nginx 的中转了。
    如果只是个人项目,可以像我一样用 Cloudflare 的 Worker 搭一个中转服务: https://corsapi.aaronlam.xyz/
    37Y37
        7
    37Y37  
       Dec 1, 2020
    建议 nginx 中转,贼简单
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5995 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 95ms · UTC 03:24 · PVG 11:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.