反应:404在部署到IIS后找不到代理
我真的需要您的帮助和建议,我已经搜索了2周,而我无法解决我的代理问题。
我正在设置以下' setUpproxy.js ',以绕过 cors ,同时请求(Web服务器)的API/端点。 但是,使用终端运行终端时,代理和原点替换仅适用于Localhost 3000。由于某些原因,部署到IIS后它不起作用,它不断获得“ 404 ”。您能告诉我在这里解决问题吗?
setupproxy.js:
app.use('/XXX.Order.API',
createProxyMiddleware({
target:'https://gcm.dellsvc',
secure: false,
changeOrigin: true
})
);
axios呼叫:
let XXX =
"/XXX.Order.API/api/v1/orders/sample"
终端/localhost:3000结果:( 200 ok ) 但是,在IIS浏览中:8080(http):(找不到404 )
web.config文件:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Text Requests" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_METHOD}" pattern="^GET$" />
<add input="{HTTP_ACCEPT}" pattern="^text/html" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I really need your help and advice on this, I have been searching for 2 weeks and I'am unable to resolve my proxy issues.
I'm setting up the below 'setupProxy.js' to bypass the CORS while requesting the API/Endpoints from the (Web Servers).
However, the proxy and Origin replacement only works from localhost 3000 when using the terminal to run it. For some reasons, It doesn't work after deploying to IIS, it keep getting "404 Not Found". Could you please tell me what should I do to fix the issue here?
setupProxy.js:
app.use('/XXX.Order.API',
createProxyMiddleware({
target:'https://gcm.dellsvc',
secure: false,
changeOrigin: true
})
);
Axios call:
let XXX =
"/XXX.Order.API/api/v1/orders/sample"
Terminal/Localhost:3000 result: (200 ok)
However, in IIS browse :8080 (http) : (404 Not Found)
web.config file:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Text Requests" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_METHOD}" pattern="^GETquot; />
<add input="{HTTP_ACCEPT}" pattern="^text/html" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了两个星期的问题。最后,我有一个令人满意的解决方案。
包装中的HTTP-Proxy-Middleware或代理。JSON仅用于开发目的(我认为)。
您创建的是绝对正确的,但是您只能在开发中使用它。
对于生产设置,仅在URL重写级别上处理。我认为这是合乎逻辑的。它与代码是分开的,如果代码中存在错误(例如指向Localhost的端点不好),则不会影响生产。
解决方案是修改在IIS中牢固存储的Web.config文件中的URL重写。
i had exactly the same problem i was dealing with for 2 weeks. Finally I have a satisfactory solution.
http-proxy-middleware or proxy in package.json is intended (in my opinion) for development purposes only.
What you have created is absolutely correct, but you can only use it in development.
For production settings, is only handled at the url rewrite level. And I think it's logical. It's separate from the code, and if there's an error in the code (eg a bad endpoint pointing to localhost), it won't affect production.
The solution is to modify the url rewrite in the web.config file, which is stored securely in IIS.