ASP VS2019 中的 CORE 和 webpack:如何配置 IIS Express 以代理 js/css 对 webpack devserver 的请求?
ASP CORE and webpack in VS2019: how to configure IIS Express to proxy js/css requests to webpack devserver?
像这样的代码
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/dist/main.css" asp-append-version="true" />
在 IIS Express 上启动请求使用 IIS Express 端口的文件,当我需要 return 来自在另一个端口上工作的 webpack devserver 的那些文件时。
有一篇文章 how to "switch" configurations and "put" required port to <link>
and <script>
references,但这里应该更容易指导 IIS Express (或自托管 ASP 核心应用程序)代理 css
和 js
.
的请求
不幸的是,这不起作用(没有效果):
<system.net>
<defaultProxy>
<proxy
proxyaddress="http://localhost:55510"
bypassonlocal="false"
/>
<!--<bypasslist>
<add address="^((?!\/dist\/).)*$" />
</bypasslist>-->
</defaultProxy>
</system.net>
如何配置 IISEXpress 或(自托管应用程序)将 /dist/*.js
和 /dist/*.css
的请求代理到 webpack devserver
?
PS It seems 那些使用 VS+webpack/devserver 的开发人员更喜欢配置 webpack devserver
以将对 html/json/images/fonts 的请求代理到 IISExpress(解决相同的问题方式,但从另一端)。为什么?
"Just write the middleware that do the proxy"
解决了。
我已经为它创建了 nuget 包:DashboardCode.AspNetCore.Http
GitHub: https://github.com/DashboardCode/AspNetCore
首先将此添加到 Startup.cs
using DashboardCode.AspNetCore.Http;
然后将此添加到 Startup.ConfigureServices()
:
serviceCollection.AddSingleton( new DevProxyMiddlewareSettings(new PathString("/dist"), new Uri("http://localhost:55555")));
然后将其添加到 Startup.Configure:
app.UseMiddleware<DevProxyMiddleware>();
在此之后所有 GET 请求都像 http://localhost:xxxx/dist/sample.js will be redirected to the http://localhost:55555/dist/sample.js
很好,它适用于两种情况:self-hosted 和 IISExpress 托管应用程序。
像这样的代码
<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/dist/main.css" asp-append-version="true" />
在 IIS Express 上启动请求使用 IIS Express 端口的文件,当我需要 return 来自在另一个端口上工作的 webpack devserver 的那些文件时。
有一篇文章 how to "switch" configurations and "put" required port to <link>
and <script>
references,但这里应该更容易指导 IIS Express (或自托管 ASP 核心应用程序)代理 css
和 js
.
不幸的是,这不起作用(没有效果):
<system.net>
<defaultProxy>
<proxy
proxyaddress="http://localhost:55510"
bypassonlocal="false"
/>
<!--<bypasslist>
<add address="^((?!\/dist\/).)*$" />
</bypasslist>-->
</defaultProxy>
</system.net>
如何配置 IISEXpress 或(自托管应用程序)将 /dist/*.js
和 /dist/*.css
的请求代理到 webpack devserver
?
PS It seems 那些使用 VS+webpack/devserver 的开发人员更喜欢配置 webpack devserver
以将对 html/json/images/fonts 的请求代理到 IISExpress(解决相同的问题方式,但从另一端)。为什么?
"Just write the middleware that do the proxy"
解决了。
我已经为它创建了 nuget 包:DashboardCode.AspNetCore.Http
GitHub: https://github.com/DashboardCode/AspNetCore
首先将此添加到 Startup.cs
using DashboardCode.AspNetCore.Http;
然后将此添加到 Startup.ConfigureServices()
:
serviceCollection.AddSingleton( new DevProxyMiddlewareSettings(new PathString("/dist"), new Uri("http://localhost:55555")));
然后将其添加到 Startup.Configure:
app.UseMiddleware<DevProxyMiddleware>();
在此之后所有 GET 请求都像 http://localhost:xxxx/dist/sample.js will be redirected to the http://localhost:55555/dist/sample.js
很好,它适用于两种情况:self-hosted 和 IISExpress 托管应用程序。