diff options
-rw-r--r-- | Timeline.Tests/Helpers/TestApplication.cs | 2 | ||||
-rw-r--r-- | Timeline/ClientApp/package.json | 1 | ||||
-rw-r--r-- | Timeline/ClientApp/yarn.lock | 8 | ||||
-rw-r--r-- | Timeline/Configs/ApplicationConfiguration.cs | 7 | ||||
-rw-r--r-- | Timeline/Startup.cs | 39 | ||||
-rw-r--r-- | Timeline/Timeline.csproj | 14 |
6 files changed, 44 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/ClientApp/yarn.lock b/Timeline/ClientApp/yarn.lock index 47c3df7e..fa6cd303 100644 --- a/Timeline/ClientApp/yarn.lock +++ b/Timeline/ClientApp/yarn.lock @@ -1569,6 +1569,13 @@ __metadata: languageName: node linkType: hard +"@types/webpack-env@npm:^1.15.2": + version: 1.15.2 + resolution: "@types/webpack-env@npm:1.15.2" + checksum: 3/571fa57efdf276b4feaf6d1fafd6b4d25a5e6f146eb517ad6c9f64ccca0146a8ed759f05428fe224ace5040983334d87259da4758fa1c18f44063243eaa9da85 + languageName: node + linkType: hard + "@types/webpack-sources@npm:*": version: 0.1.6 resolution: "@types/webpack-sources@npm:0.1.6" @@ -9623,6 +9630,7 @@ fsevents@~2.1.2: "@types/react-router": ^5.1.7 "@types/react-router-dom": ^5.1.5 "@types/reactstrap": ^8.4.2 + "@types/webpack-env": ^1.15.2 "@types/xregexp": ^4.3.0 "@typescript-eslint/eslint-plugin": ^3.0.2 "@typescript-eslint/parser": ^3.0.2 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" />
|