Угловой 6 + ASP .NET Core MVC внутри Service Fabric - PullRequest
0 голосов
/ 08 июня 2018

Я пытаюсь запустить API-интерфейс «Stateless ASP.NET Core» с Angular 6. Внутри Service Fabric.

Что я делаю

  • Создать ASP.NET Core API проект.
  • Создайте проект Angular в проекте ASP.NET Core, запустив 'ng new ClientApp.
  • Запустите ng build внутри проекта Angular, чтобы сгенерировать файлы.
  • Редактирование Startup.cs (см. Код ниже)

    Startup.cs

    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
    
        public IConfiguration Configuration { get; }
    
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
    
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }
    
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        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 =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501
    
                spa.Options.SourcePath = "ClientApp";
    
                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
    }
    

Результаты

!!Если я создаю обычный (не Service Fabric) ASP.NET Core API, этот подход работает.!!

Если я создаю то же самое внутри Service Fabric, я получаю следующие ошибки:

enter image description here

// EDIT

Решил это следующим образом https://blog.bridging -it.de / blog / blogeintrag_4480.html

Ответы [ 2 ]

0 голосов
/ 22 июня 2018

Добавьте этот пакет NuGet в свой проект:

NWebsec.AspNetCore.Middleware

и настройте что-то вроде этого:

app.UseHsts(h=> h.MaxAge(days:100).preload())

0 голосов
/ 14 июня 2018

Я смог заставить его работать, следуя руководству по этой ссылке https://blog.bridging -it.de / blog / blogeintrag_4480.html

Это на Немецком но вы должны быть в состоянии понять это с помощью Google Translate:)

...