aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-30 23:41:31 +0800
committerGitHub <noreply@github.com>2020-05-30 23:41:31 +0800
commit85360e8e755b4ce7fd1bd8531d78c06a3b9ffbdf (patch)
tree710a731990f9dc9a9475baebc5867298e6df33c4 /Timeline/Startup.cs
parentfc0521d81aa2293b94ea40b79ec0df80966c0278 (diff)
parent05c104022f71c3b19949205d5d23f07b4cd9a598 (diff)
downloadtimeline-85360e8e755b4ce7fd1bd8531d78c06a3b9ffbdf.tar.gz
timeline-85360e8e755b4ce7fd1bd8531d78c06a3b9ffbdf.tar.bz2
timeline-85360e8e755b4ce7fd1bd8531d78c06a3b9ffbdf.zip
Merge pull request #72 from crupest/merge-frontend
Merge frontend repo into this repo.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs42
1 files changed, 18 insertions, 24 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index f5220446..b6c3ff7f 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -16,6 +16,7 @@ using Timeline.Entities;
using Timeline.Formatters;
using Timeline.Helpers;
using Timeline.Models.Converters;
+using Timeline.Routes;
using Timeline.Services;
namespace Timeline
@@ -44,6 +45,7 @@ namespace Timeline
services.AddControllers(setup =>
{
setup.InputFormatters.Add(new StringInputFormatter());
+ setup.UseApiRoutePrefix("api");
})
.AddJsonOptions(options =>
{
@@ -61,29 +63,6 @@ namespace Timeline
.AddScheme<MyAuthenticationOptions, MyAuthenticationHandler>(AuthenticationConstants.Scheme, AuthenticationConstants.DisplayName, o => { });
services.AddAuthorization();
-
- if (Environment.IsDevelopment())
- {
- services.AddCors(setup =>
- {
- setup.AddDefaultPolicy(builder =>
- {
- builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
- });
- });
- }
- else
- {
- var corsConfig = Configuration.GetSection("Cors").Get<string[]>();
- services.AddCors(setup =>
- {
- setup.AddDefaultPolicy(builder =>
- {
- builder.AllowAnyHeader().AllowAnyMethod().WithOrigins(corsConfig);
- });
- });
- }
-
services.AddScoped<IPathProvider, PathProvider>();
services.AddAutoMapper(GetType().Assembly);
@@ -113,6 +92,11 @@ namespace Timeline
var pathProvider = services.GetRequiredService<IPathProvider>();
options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
+
+ services.AddSpaStaticFiles(config =>
+ {
+ config.RootPath = "ClientApp/dist";
+ });
}
@@ -126,7 +110,7 @@ namespace Timeline
app.UseRouting();
- app.UseCors();
+ app.UseSpaStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
@@ -135,6 +119,16 @@ namespace Timeline
{
endpoints.MapControllers();
});
+
+ app.UseSpa(spa =>
+ {
+ spa.Options.SourcePath = "ClientApp";
+
+ if (Environment.IsDevelopment())
+ {
+ SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "start", port: 3000);
+ }
+ });
}
}
}