aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-03 18:58:03 +0800
committercrupest <crupest@outlook.com>2020-06-03 18:58:03 +0800
commitf6efa149ee219a92065435a4a2ed240ab84162da (patch)
tree009d01b1be81108ec783ed2d225a626df6b76c42
parentd393e939282dc394c655e10ce6016725519dc3f9 (diff)
downloadtimeline-f6efa149ee219a92065435a4a2ed240ab84162da.tar.gz
timeline-f6efa149ee219a92065435a4a2ed240ab84162da.tar.bz2
timeline-f6efa149ee219a92065435a4a2ed240ab84162da.zip
Fix #87 .
-rw-r--r--Timeline.Tests/Helpers/TestApplication.cs2
-rw-r--r--Timeline/ClientApp/package.json1
-rw-r--r--Timeline/Configs/ApplicationConfiguration.cs7
-rw-r--r--Timeline/Startup.cs39
-rw-r--r--Timeline/Timeline.csproj14
5 files changed, 36 insertions, 27 deletions
diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs
index 11fe8f87..6e0a4ca6 100644
--- a/Timeline.Tests/Helpers/TestApplication.cs
+++ b/Timeline.Tests/Helpers/TestApplication.cs
@@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
+using Timeline.Configs;
using Timeline.Entities;
using Timeline.Migrations;
using Xunit;
@@ -53,6 +54,7 @@ namespace Timeline.Tests.Helpers
{
config.AddInMemoryCollection(new Dictionary<string, string>
{
+ [ApplicationConfiguration.DisableFrontEndKey] = "true",
["WorkDir"] = WorkDir
});
});
diff --git a/Timeline/ClientApp/package.json b/Timeline/ClientApp/package.json
index a84267e8..d7e0b2eb 100644
--- a/Timeline/ClientApp/package.json
+++ b/Timeline/ClientApp/package.json
@@ -29,6 +29,7 @@
"scripts": {
"start": "webpack-dev-server --config ./webpack.config.dev.js",
"build": "webpack --config ./webpack.config.prod.js",
+ "install-and-start": "yarn && webpack-dev-server --config ./webpack.config.dev.js",
"lint": "eslint src/ --ext .js --ext .jsx --ext .ts --ext .tsx"
},
"browserslist": {
diff --git a/Timeline/Configs/ApplicationConfiguration.cs b/Timeline/Configs/ApplicationConfiguration.cs
new file mode 100644
index 00000000..1fb4cf35
--- /dev/null
+++ b/Timeline/Configs/ApplicationConfiguration.cs
@@ -0,0 +1,7 @@
+namespace Timeline.Configs
+{
+ public static class ApplicationConfiguration
+ {
+ public const string DisableFrontEndKey = "DisableFrontEnd";
+ }
+}
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index afcb97ac..77b48466 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -24,10 +24,14 @@ namespace Timeline
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")]
public class Startup
{
+ private readonly bool disableFrontEnd;
+
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Environment = environment;
Configuration = configuration;
+
+ disableFrontEnd = Configuration.GetValue<bool?>(ApplicationConfiguration.DisableFrontEndKey) ?? false;
}
public IWebHostEnvironment Environment { get; }
@@ -87,10 +91,13 @@ namespace Timeline
options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
- services.AddSpaStaticFiles(config =>
+ if (!disableFrontEnd)
{
- config.RootPath = "ClientApp/dist";
- });
+ services.AddSpaStaticFiles(config =>
+ {
+ config.RootPath = "ClientApp/dist";
+ });
+ }
}
@@ -114,10 +121,13 @@ namespace Timeline
app.UseRouting();
- app.UseSpaStaticFiles(new StaticFileOptions
+ if (!disableFrontEnd)
{
- ServeUnknownFileTypes = true
- });
+ app.UseSpaStaticFiles(new StaticFileOptions
+ {
+ ServeUnknownFileTypes = true
+ });
+ }
app.UseAuthentication();
app.UseAuthorization();
@@ -127,15 +137,18 @@ namespace Timeline
endpoints.MapControllers();
});
- app.UseSpa(spa =>
+ if (!disableFrontEnd)
{
- spa.Options.SourcePath = "ClientApp";
-
- if (Environment.IsDevelopment())
+ app.UseSpa(spa =>
{
- SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "start", port: 3000);
- }
- });
+ spa.Options.SourcePath = "ClientApp";
+
+ if (Environment.IsDevelopment())
+ {
+ SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "install-and-start", port: 3000);
+ }
+ });
+ }
}
}
}
diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj
index 8231cfa8..f918b2d6 100644
--- a/Timeline/Timeline.csproj
+++ b/Timeline/Timeline.csproj
@@ -52,20 +52,6 @@
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
- <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
- <!-- Ensure Node.js is installed -->
- <Exec Command="node --version" ContinueOnError="true">
- <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
- </Exec>
- <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
- <Exec Command="yarn --version" ContinueOnError="true">
- <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
- </Exec>
- <Error Condition="'$(ErrorCode)' != '0'" Text="Yarn is required to build and run this project. To continue, please install yarn from https://yarnpkg.com/, and then restart your command prompt or IDE." />
- <Message Importance="high" Text="Restoring dependencies using 'yarn'. This may take several minutes..." />
- <Exec WorkingDirectory="$(SpaRoot)" Command="yarn" />
- </Target>
-
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="yarn" />