mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Update React Music Store to RC2
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.AspNet.SpaServices.Webpack;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using AutoMapper;
|
||||
using MusicStore.Apis;
|
||||
using MusicStore.Models;
|
||||
|
||||
@@ -15,38 +20,16 @@ namespace MusicStore
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
// Set up configuration sources.
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddEnvironmentVariables();
|
||||
Configuration = builder.Build();
|
||||
}
|
||||
|
||||
public IConfigurationRoot Configuration { get; set; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<SiteSettings>(settings =>
|
||||
{
|
||||
settings.DefaultAdminUsername = Configuration["DefaultAdminUsername"];
|
||||
settings.DefaultAdminPassword = Configuration["DefaultAdminPassword"];
|
||||
});
|
||||
|
||||
// Add MVC services to the services container.
|
||||
services.AddMvc();
|
||||
|
||||
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
|
||||
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
|
||||
// services.AddWebApiConventions();
|
||||
|
||||
|
||||
// Add EF services to the service container
|
||||
services.AddEntityFramework()
|
||||
.AddSqlite()
|
||||
.AddEntityFrameworkSqlite()
|
||||
.AddDbContext<MusicStoreContext>(options => {
|
||||
options.UseSqlite(Configuration["DbConnectionString"]);
|
||||
options.UseSqlite("Data Source=music-db.sqlite");
|
||||
});
|
||||
|
||||
// Add Identity services to the services container
|
||||
@@ -75,21 +58,13 @@ namespace MusicStore
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env)
|
||||
{
|
||||
loggerFactory.AddConsole(LogLevel.Warning);
|
||||
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
// Initialize the sample data
|
||||
SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
|
||||
|
||||
if (env.IsDevelopment()) {
|
||||
app.UseDeveloperExceptionPage();
|
||||
} else {
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
app.UseIISPlatformHandler();
|
||||
|
||||
// In dev mode, the JS/TS/etc is compiled and served dynamically and supports hot replacement.
|
||||
// In production, we assume you've used webpack to emit the prebuilt content to disk.
|
||||
if (env.IsDevelopment()) {
|
||||
@@ -100,19 +75,38 @@ namespace MusicStore
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
loggerFactory.AddConsole();
|
||||
|
||||
app.UseMvc(routes => {
|
||||
// Add MVC to the request pipeline.
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
// Matches requests that correspond to an existent controller/action pair
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
routes.MapSpaFallbackRoute(
|
||||
name: "spa-fallback",
|
||||
defaults: new { controller = "Home", action = "Index" });
|
||||
// Matches any other request that doesn't appear to have a filename extension (defined as 'having a dot in the last URI segment').
|
||||
// This means you'll correctly get 404s for /some/dir/non-existent-image.png instead of returning the SPA HTML.
|
||||
// However, it means requests like /customers/isaac.newton will *not* be mapped into the SPA, so if you need to accept
|
||||
// URIs like that you'll need to match all URIs, e.g.:
|
||||
// routes.MapRoute("spa-fallback", "{*anything}", new { controller = "Home", action = "Index" });
|
||||
// (which of course will match /customers/isaac.png too, so in that case it would serve the PNG image at that URL if one is on disk,
|
||||
// or the SPA HTML if not).
|
||||
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
|
||||
});
|
||||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseDefaultHostingConfiguration(args)
|
||||
.UseIISPlatformHandlerUrl()
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user