Skip to content

Commit ea91d52

Browse files
authored
Merge pull request #30 from damienbod/feature/improvements
Improvements
2 parents 12b117b + 8ac1d39 commit ea91d52

29 files changed

+341
-561
lines changed

.github/workflows/azure-webapps-dotnet-core.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
21
name: Build and deploy to Azure Web App
32

43
env:
5-
AZURE_WEBAPP_NAME: bff-angular-aspnetcore # set this to the name of your Azure Web App
6-
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
7-
DOTNET_VERSION: '9.0' # set this to the .NET Core version to use
4+
AZURE_WEBAPP_NAME: bff-angular-aspnetcore # set this to the name of your Azure Web App
5+
AZURE_WEBAPP_PACKAGE_PATH: "." # set this to the path to your web app project, defaults to the repository root
6+
DOTNET_VERSION: "9.0" # set this to the .NET Core version to use
87

98
on:
109
push:
11-
branches: [ "deploy" ]
10+
branches: ["deploy"]
1211
workflow_dispatch:
1312

1413
permissions:
@@ -56,14 +55,15 @@ jobs:
5655
with:
5756
name: .net-app
5857
path: ${{env.DOTNET_ROOT}}/myapp
58+
include-hidden-files: true # otherwise .well-known folder is not included
5959

6060
deploy:
6161
permissions:
6262
contents: none
6363
runs-on: ubuntu-latest
6464
needs: build
6565
environment:
66-
name: 'Development'
66+
name: "Development"
6767
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
6868

6969
steps:

.github/workflows/dotnet.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
21
name: .NET and npm build
32

43
on:
54
push:
6-
branches: [ "main" ]
5+
branches: ["main"]
76
pull_request:
8-
branches: [ "main" ]
7+
branches: ["main"]
98

109
jobs:
1110
build:
1211
runs-on: ubuntu-latest
1312

1413
steps:
15-
1614
- uses: actions/checkout@v4
1715
- name: Setup .NET
1816
uses: actions/setup-dotnet@v5

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,6 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
400+
# wwwroot (as it gets recreated on every npm run build)
401+
**/wwwroot/*

README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ The ASP.NET Core project is setup to run in development and production. In produ
1414
Configure the YARP reverse proxy to match the Angular CLI URL. This is only required in development. I always use HTTPS in development and the port needs to match the Angular CLI developement env.
1515

1616
> [!IMPORTANT]
17-
> In a real Angular project, the additional dev routes need to be added so that the __dev refresh__ works!
17+
> In a real Angular project, the additional dev routes need to be added so that the **dev refresh** works!
1818
1919
```json
20-
"UiDevServerUrl": "https://localhost:4201",
21-
"ReverseProxy": {
20+
{
21+
"UiDevServerUrl": "https://localhost:4201",
22+
"ReverseProxy": {
2223
"Routes": {
2324
"assets": {
2425
"ClusterId": "cluster1",
@@ -79,14 +80,18 @@ Configure the YARP reverse proxy to match the Angular CLI URL. This is only requ
7980
"Match": {
8081
"Path": "/{nomatterwhat}.js.map"
8182
}
83+
},
84+
"wellknown": {
85+
"ClusterId": "cluster1",
86+
"Match": {
87+
"Path": ".well-known/{**catch-all}"
88+
}
8289
}
8390
},
8491
"Clusters": {
8592
"cluster1": {
8693
"HttpClient": {
87-
"SslProtocols": [
88-
"Tls12"
89-
]
94+
"SslProtocols": ["Tls12"]
9095
},
9196
"Destinations": {
9297
"cluster1/destination1": {
@@ -96,52 +101,52 @@ Configure the YARP reverse proxy to match the Angular CLI URL. This is only requ
96101
}
97102
}
98103
}
104+
}
99105
```
100106

101107
## Setup Angular CLI
102108

103-
Add the certificates to the CLI project for example in the **/certs** folder
109+
Add the certificates to the CLI project for example in the **/certs** folder.
104110

105-
Update the Angular CLI angular.json file:
111+
Update the Angular CLI `angular.json` file:
106112

107113
```json
114+
...
108115
"serve": {
109-
"builder": "@angular/build:dev-server",
110-
"options": {
111-
"sslKey": "certs/dev_localhost.key",
112-
"sslCert": "certs/dev_localhost.pem",
113-
"port": 4201,
114-
},
116+
"builder": "@angular/build:dev-server",
117+
"options": {
118+
"sslKey": "certs/dev_localhost.key",
119+
"sslCert": "certs/dev_localhost.pem",
120+
"port": 4201
121+
}
122+
}
123+
...
115124
```
116125

117126
> [!NOTE]
118127
> The default Angular setup uses port 4200, this needs to match the YARP reverse proxy settings for development.
119128
120-
Update the outputPath for the (angular cli build) to deploy the production paths to the wwwroot of the .NET project
129+
Update the `outputPath` for the (Angular CLI build) to deploy the production paths to the `wwwroot` of the .NET project
121130

122131
```
123-
"architect": {
132+
"architect": {
124133
"build": {
125134
"builder": "@angular/build:application",
126135
"options": {
127-
"outputPath": {
136+
"outputPath": {
128137
"base": "../server/wwwroot",
129138
"browser": ""
130139
},
131140
"browser": "src/main.ts",
132-
"polyfills": [
133-
"zone.js"
134-
],
141+
"polyfills": ["zone.js"],
135142
"tsConfig": "tsconfig.app.json",
136143
"assets": [
137144
{
138145
"glob": "**/*",
139146
"input": "public"
140147
}
141148
],
142-
"styles": [
143-
"src/styles.css"
144-
]
149+
"styles": ["src/styles.css"]
145150
},
146151
```
147152

@@ -219,7 +224,7 @@ Add the Azure App registration settings to the **appsettings.Development.json**
219224
},
220225
```
221226

222-
App Service (linux plan) configuration
227+
App Service (linux plan) configuration
223228

224229
```
225230
MicrosoftEntraID__Instance --your-value--
@@ -253,24 +258,22 @@ Or just open Visual Studio and run the solution.
253258
Github actions is used for the DevOps. The build pipeline builds both the .NET project and the Angular CLI project using npm. The two projects are built in the same step because the UI project is built into the wwwroot of the server project.
254259

255260
```yaml
256-
257261
name: .NET and npm build
258262

259263
on:
260264
push:
261-
branches: [ "main" ]
265+
branches: ["main"]
262266
pull_request:
263-
branches: [ "main" ]
267+
branches: ["main"]
264268

265269
jobs:
266270
build:
267271
runs-on: ubuntu-latest
268272

269273
steps:
270-
271274
- uses: actions/checkout@v4
272275
- name: Setup .NET
273-
uses: actions/setup-dotnet@v4
276+
uses: actions/setup-dotnet@v5
274277
with:
275278
dotnet-version: 9.0.x
276279

@@ -289,7 +292,6 @@ jobs:
289292
run: dotnet build --no-restore
290293
- name: Test
291294
run: dotnet test --no-build --verbosity normal
292-
293295
```
294296
295297
## github actions Azure deployment

server/BffMicrosoftEntraID.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.10" NoWarn="NU1605" />
1212
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.10" />
13+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
1314
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" Version="4.0.1" />
1415
<PackageReference Include="Microsoft.Identity.Web" Version="4.0.1" />
1516
<PackageReference Include="Microsoft.Identity.Web.UI" Version="4.0.1" />

server/Controllers/AccountController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public ActionResult Login(string? returnUrl, string? claimsChallenge)
2323
}
2424

2525
// [ValidateAntiForgeryToken] // not needed explicitly due the the Auto global definition.
26-
[IgnoreAntiforgeryToken] // need to apply this to the form post request
2726
[Authorize]
2827
[HttpPost("Logout")]
2928
public IActionResult Logout()

server/Pages/Error.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<head>
88
<meta charset="utf-8" />
9-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0" />
1010
<title>Error</title>
1111
</head>
1212

server/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
serverOptions.AddServerHeader = false;
88
});
99

10+
builder.Services.AddOpenApi();
11+
1012
var services = builder.Services;
1113
var configuration = builder.Configuration;
1214

@@ -49,8 +51,8 @@
4951
// If you use persistent cache, you do not require this.
5052
// You can also return the 403 with the required scopes, this needs special handling for ajax calls
5153
// The check is only for single scopes
52-
services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme,
53-
options => options.Events = new RejectSessionCookieWhenAccountNotInCacheEvents(initialScopes));
54+
services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme,
55+
options => options.Events = new RejectSessionCookieWhenAccountNotInCacheEvents(initialScopes));
5456

5557
services.AddControllersWithViews(options =>
5658
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
@@ -74,6 +76,7 @@
7476

7577
app.UseDeveloperExceptionPage();
7678
app.UseWebAssemblyDebugging();
79+
app.MapOpenApi();
7780
}
7881
else
7982
{

server/appsettings.Development.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@
6868
"Match": {
6969
"Path": "/{nomatterwhat}.js.map"
7070
}
71+
},
72+
"wellknown": {
73+
"ClusterId": "cluster1",
74+
"Match": {
75+
"Path": ".well-known/{**catch-all}"
76+
}
7177
}
7278
},
7379
"Clusters": {
7480
"cluster1": {
7581
"HttpClient": {
76-
"SslProtocols": [
77-
"Tls12"
78-
]
82+
"SslProtocols": ["Tls12"]
7983
},
8084
"Destinations": {
8185
"cluster1/destination1": {

0 commit comments

Comments
 (0)