This commit is contained in:
2018-10-16 18:09:14 +00:00
parent 891052b850
commit d23f690d4e
4 changed files with 37 additions and 75 deletions

View File

@@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Http;
using AyaNova.Models;
using AyaNova.Util;
@@ -304,17 +305,20 @@ namespace AyaNova
#region STATIC FILES
_log.LogDebug("BOOT: pipeline - static files");
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
if (context.File.Name == "default.htm")
{
context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
context.Context.Response.Headers.Add("Expires", "-1");
}
}
});
app.UseStaticFiles();
//Might need the following if the page doesn't update in the client properly
//however the vue build process will automatically uniquify each build file names so maybe not required
// app.UseStaticFiles(new StaticFileOptions
// {
// OnPrepareResponse = context =>
// {
// if (context.File.Name == "index.html")
// {
// context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
// context.Context.Response.Headers.Add("Expires", "-1");
// }
// }
// });
#endregion
#region AUTH / ROLES
@@ -358,9 +362,6 @@ namespace AyaNova
_log.LogDebug("BOOT: pipeline - MVC");
app.UseMvc();
// ******************************************************************
// ******************** TESTING WIPE DB *****************************
//
@@ -410,9 +411,25 @@ namespace AyaNova
#endif
//Set autoId values
//AUTOID VALUES INITIALIZATION
ServerBootConfig.SetMostRecentAutoIdValuesFromDatabase(dbContext);
//SPA FALLBACK ROUTE
//this ensures that a refresh at the client will not 404 but rather force back to the index.html app page and then handled internally
//by the client
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
context.Response.StatusCode = 200;
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "index.html"));
}
});
//Open up the server for visitors
apiServerState.SetOpen();