|
@@ -80,7 +80,7 @@ builder.Services.AddControllers(options =>
|
|
|
{
|
|
|
//add filter by instance
|
|
|
options.Filters.Add(new InputValidationActionFilter());
|
|
|
- //add filter By the type
|
|
|
+ //add filter By the type
|
|
|
options.Filters.Add(typeof(InputValidationActionFilter));
|
|
|
});
|
|
|
//disable default model validation, because we handle this in InputValidationActionFilter and LoggingMiddleware.
|
|
@@ -110,7 +110,9 @@ builder.Services.AddSignalR(options =>
|
|
|
{
|
|
|
options.EnableDetailedErrors = true;
|
|
|
});
|
|
|
-
|
|
|
+builder.Services.AddCors(options => {
|
|
|
+ options.AddPolicy("CORSPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetIsOriginAllowed((hosts) => true));
|
|
|
+});
|
|
|
builder.Services.AddSwaggerGen(swagger =>
|
|
|
{
|
|
|
//This is to apply global headers for all requests
|
|
@@ -119,7 +121,7 @@ builder.Services.AddSwaggerGen(swagger =>
|
|
|
//This is to export enums to front
|
|
|
swagger.SchemaFilter<EnumSchemaFilter>();
|
|
|
|
|
|
- //This is to generate the Default UI of Swagger Documentation
|
|
|
+ //This is to generate the Default UI of Swagger Documentation
|
|
|
swagger.SwaggerDoc("v1", new OpenApiInfo
|
|
|
{
|
|
|
Version = "v1",
|
|
@@ -131,7 +133,7 @@ builder.Services.AddSwaggerGen(swagger =>
|
|
|
d => (d.ActionDescriptor as ControllerActionDescriptor)?.ControllerName + (d.ActionDescriptor as ControllerActionDescriptor)?.ActionName
|
|
|
);
|
|
|
|
|
|
- // To Enable authorization using Swagger (JWT)
|
|
|
+ // To Enable authorization using Swagger (JWT)
|
|
|
swagger.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
|
|
{
|
|
|
Name = "Authorization",
|
|
@@ -173,13 +175,13 @@ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.AP
|
|
|
|
|
|
app.UseRouting(); // <-- Add UseRouting() here
|
|
|
|
|
|
-app.UseCors(x => x
|
|
|
- .WithOrigins("https://api.mtwork.com", "https://mtworkhrclient.azurewebsites.net", "http://localhost:4200", "https://www.mtwork.com") // Allowed origins without trailing slash
|
|
|
- .AllowAnyMethod()
|
|
|
- .AllowAnyHeader()
|
|
|
- .AllowCredentials() // Allows credentials
|
|
|
-);
|
|
|
-
|
|
|
+//app.UseCors(x => x
|
|
|
+// .WithOrigins("https://api.mtwork.com", "https://mtworkhrclient.azurewebsites.net", "http://localhost:4200", "https://www.mtwork.com") // Allowed origins without trailing slash
|
|
|
+// .AllowAnyMethod()
|
|
|
+// .AllowAnyHeader()
|
|
|
+// .AllowCredentials() // Allows credentials
|
|
|
+//);
|
|
|
+app.UseCors("CORSPolicy");
|
|
|
|
|
|
|
|
|
|