首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Azure Windows服务器( IIS8 VM)上部署React应用程序

在Azure Windows服务器( IIS8 VM)上部署React应用程序
EN

Stack Overflow用户
提问于 2019-04-02 22:51:16
回答 1查看 347关注 0票数 0

请帮帮忙。我有一个react应用程序,当从VS2017启动时,它可以完美地工作。当相同的应用程序托管在Azure VM (IIS-8,Windows Server)上时,会给我404或500个错误。

我的托管目录结构适用于我的.Net应用程序和混合的.net和React应用程序,但不适用于我的新React only应用程序。

我的目录结构是wwwroot>Dashboard。我将我的产品构建复制到此仪表板文件夹。

我的webconfig是:

代码语言:javascript
复制
`<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
          <system.webServer>
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath="dotnet" arguments=".\Dashboard.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
            <rewrite>
                    <rules>
                        <rule name="React Routes" stopProcessing="true">
                            <match url=".*" />
                                <conditions logicalGrouping="MatchAll">
                                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                                    <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                                </conditions>
                            <action type="Rewrite" url="/" />
                        </rule>
                    </rules>
                </rewrite>
            </system.webServer>
        </location>
    </configuration>`

enter image description here

EN

回答 1

Stack Overflow用户

发布于 2019-04-04 10:46:07

据我所知,asp.net核心应用程序使用services.AddSpaStaticFiles来服务React应用程序,而不是使用url重写。

我建议您可以检查一下Startup.cs的Configure和ConfigureServices方法,以确保您已经添加了SPA设置。

代码如下:

代码语言:javascript
复制
     public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        // In production, the React files will be served from this directory
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = "ClientApp/build";
        });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseSpaStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller}/{action=Index}/{id?}");
        });

        app.UseSpa(spa =>
        {
            //the source path of the react application
            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseReactDevelopmentServer(npmScript: "start");
            }
        });
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55477691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档