繁体   English   中英

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

[英]Webpack Dev Server proxy doesn't redirect to api backend

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

尝试添加

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

希望对您有所帮助

我的 Express 服务器在http://localhost:3000上运行,我正在尝试使用 Webpack-DevServer 的代理功能通过 Devserver(http://localhost:8080) 上的/api路径访问我的后端服务器 API。

我遇到了和你一样的问题,我有 2 个解决方案(在proxy密钥中评论)

devServer: {
        port: 8080,
        proxy: {
            // '/api': 'http://[::1]:3000'
            // '/api/**': 'http://localhost:3000/'
        },
        historyApiFallback: true
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM