【问题标题】:Webpack Dev Server proxy doesn't redirect to api backendWebpack Dev Server 代理不会重定向到 api 后端
【发布时间】:2017-10-04 10:27:04
【问题描述】:

我尝试将我的“http://localhost:3000/api/”路径重定向到在 apache 服务器中运行的“http://example.com/api/”。

这是我的 devServer 配置:

devServer: {
    publicPath: '/build/',
    port: 3000,
    proxy: {
        '/api': {
            target: 'http://gestios.loc/api'
        }
    },
    historyApiFallback: true
}

当我尝试访问 http://localhost:3000/api/calltek/apps?permalink=empresas 时收到 404 错误。

Request URL:http://localhost:3000/api/calltek/apps?permalink=empresas
Request Method:GET
Status Code:404 Not Found
Remote Address:127.0.0.1:3000
Referrer Policy:no-referrer-when-downgrade

HTTP/1.1 404 Not Found
X-Powered-By: Express
date: Fri, 05 May 2017 18:13:42 GMT
server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28
vary: accept-language,accept-charset
accept-ranges: bytes
connection: close
transfer-encoding: chunked
content-type: text/html
content-language: es

【问题讨论】:

标签: javascript angularjs apache webpack webpack-dev-server


【解决方案1】:

尝试添加

devServer: {
    publicPath: '/build/',
    port: 3000,
    proxy: {
        '/api': {
            target: 'http://gestios.loc/api'
            secure: false,
            changeOrigin: true
        }
    },
    historyApiFallback: true
}

希望对你有帮助

【讨论】:

  • changeOrigin 属性对我来说很重要。我正在使用 Webpack 4 和 OSX10。谢谢!
猜你喜欢
  • 2016-11-27
  • 2017-09-09
  • 2016-06-02
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 2019-05-02
相关资源
最近更新 更多