Skip to content

Commit 8e79ac1

Browse files
authored
Client upgrade client app to ASP.NET Core 2 (#15)
1 parent 760c1d5 commit 8e79ac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+161565
-3279
lines changed

.gitignore

Lines changed: 237 additions & 256 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Mvc;
6-
7-
namespace ApiApp.Controllers
8-
{
9-
[Route("api/[controller]")]
10-
public class ValuesController : Controller
11-
{
12-
// GET api/values
13-
[HttpGet]
14-
public IEnumerable<string> Get()
15-
{
16-
return new string[] { "value1", "value2" };
17-
}
18-
19-
// GET api/values/5
20-
[HttpGet("{id}")]
21-
public string Get(int id)
22-
{
23-
return "value";
24-
}
25-
26-
// POST api/values
27-
[HttpPost]
28-
public void Post([FromBody]string value)
29-
{
30-
}
31-
32-
// PUT api/values/5
33-
[HttpPut("{id}")]
34-
public void Put(int id, [FromBody]string value)
35-
{
36-
}
37-
38-
// DELETE api/values/5
39-
[HttpDelete("{id}")]
40-
public void Delete(int id)
41-
{
42-
}
43-
}
44-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace ApiApp.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
public class ValuesController : Controller
11+
{
12+
// GET api/values
13+
[HttpGet]
14+
public IEnumerable<string> Get()
15+
{
16+
return new string[] { "value1", "value2" };
17+
}
18+
19+
// GET api/values/5
20+
[HttpGet("{id}")]
21+
public string Get(int id)
22+
{
23+
return "value";
24+
}
25+
26+
// POST api/values
27+
[HttpPost]
28+
public void Post([FromBody]string value)
29+
{
30+
}
31+
32+
// PUT api/values/5
33+
[HttpPut("{id}")]
34+
public void Put(int id, [FromBody]string value)
35+
{
36+
}
37+
38+
// DELETE api/values/5
39+
[HttpDelete("{id}")]
40+
public void Delete(int id)
41+
{
42+
}
43+
}
44+
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "http://localhost:5001/",
7-
"sslPort": 0
8-
}
9-
},
10-
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"environmentVariables": {
14-
"ASPNETCORE_ENVIRONMENT": "Development"
15-
}
16-
},
17-
"ApiApp": {
18-
"commandName": "Project",
19-
"applicationUrl": "http://localhost:5001"
20-
}
21-
}
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:5001/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"environmentVariables": {
14+
"ASPNETCORE_ENVIRONMENT": "Development"
15+
}
16+
},
17+
"ApiApp": {
18+
"commandName": "Project",
19+
"applicationUrl": "http://localhost:5001"
20+
}
21+
}
2222
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{
2-
"Logging": {
3-
"IncludeScopes": false,
4-
"LogLevel": {
5-
"Default": "Debug",
6-
"System": "Information",
7-
"Microsoft": "Information"
8-
}
9-
}
10-
}
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
}
10+
}

ApiApp/appsettings.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{
2-
"Logging": {
3-
"IncludeScopes": false,
4-
"LogLevel": {
5-
"Default": "Warning"
6-
}
7-
}
8-
}
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Warning"
6+
}
7+
}
8+
}

ClientApp/ClientApp.csproj

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
1-
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
23
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
45
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
6+
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
57
<IsPackable>false</IsPackable>
68
</PropertyGroup>
9+
710
<ItemGroup>
8-
<PackageReference Include="IdentityModel" Version="2.9.1" />
9-
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
10-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="1.1.2" />
12-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
13-
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
14-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
15-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
11+
<PackageReference Include="IdentityModel" Version="2.10.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
1613
</ItemGroup>
14+
1715
<ItemGroup>
18-
<!-- Files not to show in IDE -->
19-
<None Remove="yarn.lock" />
16+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
17+
</ItemGroup>
2018

19+
<ItemGroup>
2120
<!-- Files not to publish (note that the 'dist' subfolders are re-added below) -->
2221
<Content Remove="ClientApp\**" />
2322
</ItemGroup>
24-
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
23+
24+
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
25+
<!-- Ensure Node.js is installed -->
26+
<Exec Command="node --version" ContinueOnError="true">
27+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
28+
</Exec>
29+
<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." />
30+
31+
<!-- In development, the dist files won't exist on the first run or when cloning to
32+
a different machine, so rebuild them if not already present. -->
33+
<Message Importance="high" Text="Performing first-run Webpack build..." />
34+
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
35+
<Exec Command="node node_modules/webpack/bin/webpack.js" />
36+
</Target>
37+
38+
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
2539
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
2640
<Exec Command="npm install" />
2741
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { AppModuleShared } from './app.module.shared';
4+
import { AppComponent } from './components/app/app.component';
5+
6+
@NgModule({
7+
bootstrap: [AppComponent],
8+
imports: [
9+
BrowserModule,
10+
AppModuleShared
11+
],
12+
providers: [
13+
AppModuleShared
14+
]
15+
})
16+
export class AppModule {
17+
}
18+
19+

ClientApp/ClientApp/app/app.module.client.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

ClientApp/ClientApp/app/app.module.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { NgModule } from '@angular/core';
22
import { ServerModule } from '@angular/platform-server';
3-
import { sharedConfig } from './app.module.shared';
3+
import { AppModuleShared } from './app.module.shared';
4+
import { AppComponent } from './components/app/app.component';
45

56
@NgModule({
6-
bootstrap: sharedConfig.bootstrap,
7-
declarations: sharedConfig.declarations,
7+
bootstrap: [AppComponent],
88
imports: [
99
ServerModule,
10-
...sharedConfig.imports
10+
AppModuleShared
1111
],
1212
providers: [
13-
...sharedConfig.providers
13+
AppModuleShared
1414
]
1515
})
1616
export class AppModule {
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { FormsModule } from '@angular/forms';
4+
import { HttpModule } from '@angular/http';
25
import { RouterModule } from '@angular/router';
36

47
import { AppComponent } from './components/app/app.component'
@@ -8,11 +11,10 @@ import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
811
import { CounterComponent } from './components/counter/counter.component';
912
import { UnauthorizedComponent } from './components/unauthorized/unauthorized.component';
1013

11-
import { AuthModule } from 'angular-auth-oidc-client';
14+
import { AuthModule, OidcSecurityService } from 'angular-auth-oidc-client';
1215
import { AuthService } from './components/services/auth.service';
1316

14-
export const sharedConfig: NgModule = {
15-
bootstrap: [ AppComponent ],
17+
@NgModule({
1618
declarations: [
1719
AppComponent,
1820
NavMenuComponent,
@@ -23,17 +25,32 @@ export const sharedConfig: NgModule = {
2325
],
2426
imports: [
2527
AuthModule.forRoot(),
28+
CommonModule,
29+
HttpModule,
30+
FormsModule,
2631
RouterModule.forRoot([
2732
{ path: '', redirectTo: 'home', pathMatch: 'full' },
2833
{ path: 'home', component: HomeComponent },
2934
{ path: 'unauthorized', component: UnauthorizedComponent },
3035
{ path: 'counter', component: CounterComponent },
31-
{ path: 'fetch-data', component: FetchDataComponent },
36+
{ path: 'fetch-data', component: FetchDataComponent },
3237
{ path: '**', redirectTo: 'home' }
3338
])
3439
],
35-
providers: [
40+
providers: [
3641
AuthService,
37-
{ provide: 'API_URL', useValue: "http://localhost:5001/api/" }
42+
OidcSecurityService,
43+
{ provide: 'ORIGIN_URL', useFactory: getBaseUrl },
44+
{ provide: 'API_URL', useFactory: getApiUrl }
3845
]
39-
};
46+
})
47+
export class AppModuleShared {
48+
}
49+
50+
export function getBaseUrl() {
51+
return document.getElementsByTagName('base')[0].href;
52+
}
53+
54+
export function getApiUrl() {
55+
return "http://localhost:5001/api/";
56+
}

0 commit comments

Comments
 (0)