-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template for Single Page Applications
- Loading branch information
1 parent
17b5e2b
commit 694fa48
Showing
11 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Templates/SinglePageApplication/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<Nullable>enable</Nullable> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
|
||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
|
||
<PackageReference Include="GenHTTP.Testing" Version="8.3.0" /> | ||
|
||
<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" /> | ||
|
||
</ItemGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
Templates/SinglePageApplication/$safeprojectname$.Tests/ApplicationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using GenHTTP.Testing; | ||
|
||
namespace $safeprojectname$.Tests | ||
{ | ||
|
||
[TestClass] | ||
public class ApplicationTests | ||
{ | ||
|
||
[TestMethod] | ||
public async Task TestRoot() | ||
{ | ||
using var runner = TestHost.Run(Project.Setup()); | ||
|
||
using var response = await runner.GetResponseAsync(); | ||
|
||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Templates/SinglePageApplication/$safeprojectname$/$safeprojectname$.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<Nullable>enable</Nullable> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
|
||
<AssemblyVersion>0.1.0.0</AssemblyVersion> | ||
<FileVersion>0.1.0.0</FileVersion> | ||
<Version>0.1.0</Version> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
||
<PackageReference Include="GenHTTP.Core" Version="8.3.1" /> | ||
|
||
<PackageReference Include="GenHTTP.Modules.SinglePageApplications" Version="8.3.0" /> | ||
|
||
</ItemGroup> | ||
|
||
</Project> |
19 changes: 19 additions & 0 deletions
19
Templates/SinglePageApplication/$safeprojectname$/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using GenHTTP.Engine; | ||
|
||
using GenHTTP.Modules.Practices; | ||
|
||
using $safeprojectname$; | ||
|
||
var project = Project.Setup(); | ||
|
||
// hosts your app on http://localhost:8080 | ||
return Host.Create() | ||
.Handler(project) | ||
.Defaults() | ||
.Console() | ||
//-:cnd:noEmit | ||
#if DEBUG | ||
.Development() | ||
#endif | ||
//+:cnd:noEmit | ||
.Run(); |
46 changes: 46 additions & 0 deletions
46
Templates/SinglePageApplication/$safeprojectname$/Project.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using GenHTTP.Api.Content; | ||
|
||
using GenHTTP.Modules.IO; | ||
using GenHTTP.Modules.Layouting; | ||
using GenHTTP.Modules.SinglePageApplications; | ||
|
||
namespace $safeprojectname$ | ||
{ | ||
|
||
public static class Project | ||
{ | ||
|
||
public static IHandlerBuilder Setup() | ||
{ | ||
// | ||
// depending on your needs, update this section to define where your | ||
// single page application distribution files are loaded from | ||
// | ||
// if you would like to productively host your SPA somewhere, you might want to ... | ||
// | ||
// - use a debug directive to load another directory locally as in production | ||
// - use an environment variable to pass the path to the application | ||
// - ... | ||
// | ||
var distRoot = ResourceTree.FromDirectory(@"C:\Projects\some-app\dist\some-app\browser\"); | ||
|
||
var spa = SinglePageApplication.From(distRoot) | ||
.ServerSideRouting(); | ||
|
||
// | ||
// if you would like to host some API for your app, you can create | ||
// services and add them to your app's layout here (e.g. via AddService<T>) | ||
// | ||
// for this purpose, there are various frameworks and nuget packages available: | ||
// | ||
// - web services (https://genhttp.org/documentation/content/webservices) | ||
// - functional handlers (https://genhttp.org/documentation/content/functional) | ||
// - controllers (https://genhttp.org/documentation/content/controllers) | ||
// | ||
return Layout.Create() | ||
.Add(spa); | ||
} | ||
|
||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Templates/SinglePageApplication/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Andreas Nägeli", | ||
"classifications": [ "GenHTTP", "SPA", "Single Page Application" ], | ||
"identity": "GenHTTP.Templates.SinglePageApplication", | ||
"name": "GenHTTP: Single Page Application (SPA)", | ||
"shortName": "genhttp-spa", | ||
"sourceName": "$safeprojectname$", | ||
"description": "A project template to host a Single Page Application using the GenHTTP webserver", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
WORKDIR /source | ||
|
||
# copy csproj and restore as distinct layers | ||
COPY $safeprojectname$/*.csproj . | ||
RUN dotnet restore -r linux-arm | ||
|
||
# copy and publish app and libraries | ||
COPY $safeprojectname$/ . | ||
RUN dotnet publish -c release -o /app -r linux-arm --no-restore /p:PublishTrimmed=true /p:TrimMode=Link | ||
|
||
# final stage/image | ||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm32v7 | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
|
||
ENTRYPOINT ["./$safeprojectname$"] | ||
|
||
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
WORKDIR /source | ||
|
||
# copy csproj and restore as distinct layers | ||
COPY $safeprojectname$/*.csproj . | ||
RUN dotnet restore -r linux-arm64 | ||
|
||
# copy and publish app and libraries | ||
COPY $safeprojectname$/ . | ||
RUN dotnet publish -c release -o /app -r linux-arm64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link | ||
|
||
# final stage/image | ||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm64v8 | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
|
||
ENTRYPOINT ["./$safeprojectname$"] | ||
|
||
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build | ||
WORKDIR /source | ||
|
||
# copy csproj and restore as distinct layers | ||
COPY $safeprojectname$/*.csproj . | ||
RUN dotnet restore -r linux-musl-x64 | ||
|
||
# copy and publish app and libraries | ||
COPY $safeprojectname$/ . | ||
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link | ||
|
||
# final stage/image | ||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
|
||
ENTRYPOINT ["./$safeprojectname$"] | ||
|
||
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# $safeprojectname$ | ||
|
||
*Add your project description here.* | ||
|
||
## Development | ||
|
||
To build this project from source, checkout this repository and execute | ||
the following commands in your terminal. This requires the | ||
[.NET SDK](https://dotnet.microsoft.com/download) to be installed. | ||
|
||
``` | ||
cd $safeprojectname$ | ||
dotnet run | ||
``` | ||
|
||
This will make the service available at http://localhost:8080/. | ||
|
||
## Deployment | ||
|
||
To run this project with [Docker](https://www.docker.com/), run the | ||
following commands in your terminal (and adjust the first line | ||
depending on your platform). | ||
|
||
``` | ||
docker build -f Dockerfile.linux-x64 -t $safeprojectname$ . | ||
docker run -p 8080:8080 $safeprojectname$ | ||
``` | ||
|
||
## About | ||
|
||
This project uses the [GenHTTP webserver](https://genhttp.org/) to | ||
implement it's functionality. |