Skip to content

Instantly share code, notes, and snippets.

@MufidJamaluddin
Created July 15, 2020 15:29
Show Gist options
  • Save MufidJamaluddin/470b656799495159a083ea9cfed15f3a to your computer and use it in GitHub Desktop.
Save MufidJamaluddin/470b656799495159a083ea9cfed15f3a to your computer and use it in GitHub Desktop.
namespace IssueTracker
{
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IssueTrackerDbContext dbContext, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
dbContext?.Database.Migrate();
SeedRunner.Run(dbContext);
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
// Middleware Yang Wajibin HTTPS
if (appConfig.UseHttps)
{
app.UseHttpsRedirection();
}
// Middleware Buat Handle Permintaan Static File
app.UseStaticFiles();
// Middleware Buat Handle Permintaan Static File SPA (AngularJS, ReactJS, VueJS, dsb)
app.UseSpaStaticFiles();
// Middleware Buat Routing Aplikasi
app.UseRouting();
// Custom Middleware Dapetin JWT dari Cookie
app.UseJwtInCookie();
// Middleware Otentikasi (Login)
app.UseAuthentication();
// Middleare Otorisasi (Role Login)
app.UseAuthorization();
// Mapping Permintaan URL dengan Controller
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
// Pakai URL SPA
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment