Git Product home page Git Product logo

backstage-management's People

Contributors

geniusfunny avatar

Watchers

 avatar

Forkers

dmxhna wizzstudio

backstage-management's Issues

使用Nginx反向代理跨域

由于项目前后端分离且后端真实接口已出,所以我开发时首先考虑通过跨域获取真实接口数据配合前端开发。(赶工期啊:)
根据create-react-app官方提示,在package.json中添加字段
"proxy": "http://admin.xiaoyaoeden.top"
emmm 🤭无效 😂
所以改为使用Nginx反向代理跨域😊
current origin:http://localhost:3000
target origin:http://admin.xiaoyaoeden.top

👇👇👇 过程如下(macOS)

安装

brew install nginx

修改配置

首先进入nginx的配置文件

vim /usr/local/etc/nginx/nginx.conf

增加如下一个server

server {
       listen       3001;
       server_name  localhost;

        location / {
           proxy_pass http://localhost:3000;
        }

        location /api/ {
           add_header Access-Control-Allow-Origin *;
           proxy_pass http://admin.xiaoyaoeden.top;
        }
    }

重启Nginx服务

brew services restart nginx

测试

打开localhost:3000,跨域问题解决了,现在可以开开心心的测试接口啦

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.