簡體   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