Webpack Dev Server代理不会重定向到api后端

时间:2017-05-05 20:37:52

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

我尝试将“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

1 个答案:

答案 0 :(得分:5)

尝试添加

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

我希望它有所帮助