public NoteController(RayNoteDbContext dbContext) { _dbContext = dbContext; sha256 = SHA256.Create(); IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); jwtEncoder = new JwtEncoder(algorithm, serializer, urlEncoder); var provider = new UtcDateTimeProvider(); IJwtValidator validator = new JwtValidator(serializer, provider); jwtDecoder = new JwtDecoder(serializer, validator, urlEncoder, algorithm); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RayNoteDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(MyAllowSpecificOrigins); app.UseAuthorization(); dbContext.Database.EnsureCreated(); app.Use(async(context, next) => { await next(); // Exam the request type is for api or web. if (context.Response.StatusCode == 404 && // Resource not found. !System.IO.Path.HasExtension(context.Request.Path.Value) && // Without file extension. !context.Request.Path.Value.StartsWith("/api")) // Url without '/api'. { context.Request.Path = "/index.html"; // Route to /index.html. context.Response.StatusCode = 200; // Adjust status code. await next(); } }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }