diff options
author | crupest <crupest@outlook.com> | 2020-06-05 16:51:42 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-05 16:51:42 +0800 |
commit | e1ccc1cfe43a44e975dba3a412522f8ea5760ca4 (patch) | |
tree | a2404f848cc07669cd63879c573a5831fb2593b9 | |
parent | ae19c40c795e14e8793744b7520e103523f6bda4 (diff) | |
download | timeline-e1ccc1cfe43a44e975dba3a412522f8ea5760ca4.tar.gz timeline-e1ccc1cfe43a44e975dba3a412522f8ea5760ca4.tar.bz2 timeline-e1ccc1cfe43a44e975dba3a412522f8ea5760ca4.zip |
feat(back): Add option to use proxy to serve front end in development.
-rw-r--r-- | Timeline/Configs/ApplicationConfiguration.cs | 1 | ||||
-rw-r--r-- | Timeline/Properties/launchSettings.json | 1 | ||||
-rw-r--r-- | Timeline/Startup.cs | 14 |
3 files changed, 12 insertions, 4 deletions
diff --git a/Timeline/Configs/ApplicationConfiguration.cs b/Timeline/Configs/ApplicationConfiguration.cs index 1fb4cf35..2715f84e 100644 --- a/Timeline/Configs/ApplicationConfiguration.cs +++ b/Timeline/Configs/ApplicationConfiguration.cs @@ -3,5 +3,6 @@ public static class ApplicationConfiguration
{
public const string DisableFrontEndKey = "DisableFrontEnd";
+ public const string FrontEndProxyOnlyKey = "FrontEndProxyOnly";
}
}
diff --git a/Timeline/Properties/launchSettings.json b/Timeline/Properties/launchSettings.json index 10c819c0..daa4b011 100644 --- a/Timeline/Properties/launchSettings.json +++ b/Timeline/Properties/launchSettings.json @@ -4,6 +4,7 @@ "commandName": "Project", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_FRONTENDPROXYONLY": "true", "ASPNETCORE_WORKDIR": "D:\\timeline-development" } }, diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 77b48466..35c47712 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -21,7 +21,6 @@ using Timeline.Services; namespace Timeline
{
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")]
public class Startup
{
private readonly bool disableFrontEnd;
@@ -91,7 +90,7 @@ namespace Timeline options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
- if (!disableFrontEnd)
+ if (!disableFrontEnd && !Environment.IsDevelopment())
{
services.AddSpaStaticFiles(config =>
{
@@ -121,7 +120,7 @@ namespace Timeline app.UseRouting();
- if (!disableFrontEnd)
+ if (!disableFrontEnd && !Environment.IsDevelopment())
{
app.UseSpaStaticFiles(new StaticFileOptions
{
@@ -145,7 +144,14 @@ namespace Timeline if (Environment.IsDevelopment())
{
- SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "install-and-start", port: 3000);
+ if (Configuration.GetValue<bool?>(ApplicationConfiguration.FrontEndProxyOnlyKey) ?? false)
+ {
+ spa.UseProxyToSpaDevelopmentServer(new UriBuilder("http", "localhost", 3000).Uri);
+ }
+ else
+ {
+ SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "install-and-start", port: 3000);
+ }
}
});
}
|