代码之家  ›  专栏  ›  技术社区  ›  gyc

部署在AmazonS3上的Vue应用程序发出的AXIOS请求返回站点索引

  •  0
  • gyc  · 技术社区  · 8 年前

    CORS配置与默认配置相同。

    <script>history.pushState({}, "Application entry", location.hash.substring(2));</script>
    

    我还有一个代理配置块:

    proxy: {
      // proxy all requests starting with /v1
      '/v1': {
        target: 'http://some-app-deployed-on.elasticbeanstalk.com/v1',
        changeOrigin: true,
        pathRewrite: {
          '^/v1': '',
        },
      },
    

      location /v1 {
          proxy_pass          http://127.0.0.1:5000;
          proxy_http_version  1.1;
          add_header          "Access-Control-Allow-Origin" "*";
          proxy_set_header    Connection          $connection_upgrade;
          proxy_set_header    Upgrade             $http_upgrade;
          proxy_set_header    Host                $host;
          proxy_set_header    X-Real-IP           $remote_addr;
          proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
      }
    

    请求是一个简单的http.get

      axios
        .get(`/v1/endpoint/${param}`)
        .then((response) => {
          console.log(response);
        })
    

    catch

    response.data

    2 回复  |  直到 8 年前
        1
  •  0
  •   Alex Tunbridge    8 年前

      axios
        .get(`/v1/endpoint`, params: {
          param
        })
        .then((response) => {
          console.log(response);
        })
    

    甚至

      axios
        .get('/v1/endpoint/' + param)
        .then((response) => {
          console.log(response); 
      })
    
        2
  •  0
  •   gyc    8 年前

    proxy: {
      // proxy all requests starting with /v1
      '/v1': {
        target: 'http://some-app-deployed-on.elasticbeanstalk.com/v1',
        changeOrigin: true,
        pathRewrite: {
          '^/v1': '',
        },
      },
    

    只有在dev环境中运行时才有效。

    axios
        .get(`/v1/endpoint/${param}`)
        .then((response) => {
          console.log(response);
        })
    

    /v1/endpoint/${param} 改为 http://some-app-deployed-on.elasticbeanstalk.com/v1/endpoint/${param}

    编辑:

    推荐文章