-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to return 404 status code #1
- configure project structure - configure lazy loaded modules
- Loading branch information
Showing
35 changed files
with
253 additions
and
33 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
<h1>{{ title }}</h1> | ||
<router-outlet></router-outlet> |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; | ||
import { PLATFORM_ID, APP_ID, Inject } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
import { AppComponent } from '@angular-universal/app.component'; | ||
import { AppComponent } from './app.component'; | ||
import { CoreModule } from './modules/core/core.module'; | ||
import { SharedModule } from './modules/shared/shared.module'; | ||
|
||
@NgModule({ | ||
imports: [BrowserModule.withServerTransition({ appId: 'angular-universal' }), BrowserTransferStateModule], | ||
imports: [RouterModule, CoreModule, SharedModule], | ||
declarations: [AppComponent], | ||
providers: [], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule { | ||
constructor(@Inject(PLATFORM_ID) private platformId: Object, @Inject(APP_ID) private appId: string) { | ||
const platform = isPlatformBrowser(platformId) ? 'in the browser' : 'on the server'; | ||
|
||
console.log(`Running ${platform} with appId=${appId}`); | ||
} | ||
} | ||
export class AppModule {} |
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
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,3 @@ | ||
import { environment } from '../../environments/environment'; | ||
|
||
export const AppSettingsConfig: any = environment; |
Empty file.
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,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; | ||
|
||
import { RoutingModule } from '../routing/routing.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule.withServerTransition({ appId: 'angular-universal' }), | ||
BrowserTransferStateModule, | ||
RoutingModule, | ||
], | ||
}) | ||
export class CoreModule {} |
Empty file.
Empty file.
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions
18
...n/src/app/modules/core/services/http-response-status/http-response-status.service.spec.ts
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,18 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { HttpResponseStatusService } from './http-response-status.service'; | ||
|
||
describe('HttpResponseStatusService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [HttpResponseStatusService], | ||
}); | ||
}); | ||
|
||
it( | ||
'should be created', | ||
inject([HttpResponseStatusService], (service: HttpResponseStatusService) => { | ||
expect(service).toBeTruthy(); | ||
}) | ||
); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...cation/src/app/modules/core/services/http-response-status/http-response-status.service.ts
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,22 @@ | ||
import { Inject, Injectable, Optional } from '@angular/core'; | ||
import { RESPONSE } from '@nguniversal/express-engine/tokens'; | ||
|
||
import { CoreModule } from '../../core.module'; | ||
|
||
@Injectable({ | ||
providedIn: CoreModule, | ||
}) | ||
export class HttpResponseStatusService { | ||
constructor( | ||
@Optional() | ||
@Inject(RESPONSE) | ||
private res: any | ||
) {} | ||
|
||
public setStatus(code: number, message: string): void { | ||
if (this.res) { | ||
this.res.statusCode = code; | ||
this.res.statusMessage = message; | ||
} | ||
} | ||
} |
Empty file.
16 changes: 16 additions & 0 deletions
16
project/application/src/app/modules/home/home-routing.module.ts
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,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
|
||
import { HomeComponent } from './home.component'; | ||
|
||
export const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: HomeComponent, | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
}) | ||
export class HomeRoutingModule {} |
Empty file.
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 @@ | ||
<h1>{{ title }}</h1> |
36 changes: 36 additions & 0 deletions
36
project/application/src/app/modules/home/home.component.spec.ts
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,36 @@ | ||
import { TestBed, async } from '@angular/core/testing'; | ||
|
||
import { HomeComponent } from './home.component'; | ||
|
||
describe('HomeComponent', () => { | ||
beforeEach( | ||
async(() => { | ||
TestBed.configureTestingModule({ declarations: [HomeComponent] }).compileComponents(); | ||
}) | ||
); | ||
it( | ||
'should create the app', | ||
async(() => { | ||
const fixture = TestBed.createComponent(HomeComponent); | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
}) | ||
); | ||
it( | ||
`should have as title 'Home page!'`, | ||
async(() => { | ||
const fixture = TestBed.createComponent(HomeComponent); | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app.title).toEqual('Home page!'); | ||
}) | ||
); | ||
it( | ||
'should render title in a h1 tag', | ||
async(() => { | ||
const fixture = TestBed.createComponent(HomeComponent); | ||
fixture.detectChanges(); | ||
const compiled = fixture.debugElement.nativeElement; | ||
expect(compiled.querySelector('h1').textContent).toContain('Home page!'); | ||
}) | ||
); | ||
}); |
10 changes: 10 additions & 0 deletions
10
project/application/src/app/modules/home/home.component.ts
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,10 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-home', | ||
templateUrl: './home.component.html', | ||
styleUrls: ['./home.component.css'], | ||
}) | ||
export class HomeComponent { | ||
title = 'Home page!'; | ||
} |
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,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { HomeRoutingModule } from './home-routing.module'; | ||
import { HomeComponent } from './home.component'; | ||
|
||
@NgModule({ | ||
imports: [HomeRoutingModule], | ||
declarations: [HomeComponent], | ||
}) | ||
export class HomeModule {} |
Empty file.
16 changes: 16 additions & 0 deletions
16
project/application/src/app/modules/not-found/not-found-routing.module.ts
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,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
|
||
import { NotFoundComponent } from './not-found.component'; | ||
|
||
export const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: NotFoundComponent, | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
}) | ||
export class NotFoundRoutingModule {} |
Empty file.
1 change: 1 addition & 0 deletions
1
project/application/src/app/modules/not-found/not-found.component.html
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 @@ | ||
<h1>{{ title }}</h1> |
41 changes: 41 additions & 0 deletions
41
project/application/src/app/modules/not-found/not-found.component.spec.ts
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,41 @@ | ||
import { TestBed, async } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { NotFoundComponent } from './not-found.component'; | ||
import { CoreModule } from '../core/core.module'; | ||
|
||
describe('NotFoundComponent', () => { | ||
beforeEach( | ||
async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [NotFoundComponent], | ||
imports: [CoreModule, RouterTestingModule], | ||
}).compileComponents(); | ||
}) | ||
); | ||
it( | ||
'should create the app', | ||
async(() => { | ||
const fixture = TestBed.createComponent(NotFoundComponent); | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
}) | ||
); | ||
it( | ||
`should have as title 'Not found page!'`, | ||
async(() => { | ||
const fixture = TestBed.createComponent(NotFoundComponent); | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app.title).toEqual('Not found page!'); | ||
}) | ||
); | ||
it( | ||
'should render title in a h1 tag', | ||
async(() => { | ||
const fixture = TestBed.createComponent(NotFoundComponent); | ||
fixture.detectChanges(); | ||
const compiled = fixture.debugElement.nativeElement; | ||
expect(compiled.querySelector('h1').textContent).toContain('Not found page!'); | ||
}) | ||
); | ||
}); |
18 changes: 18 additions & 0 deletions
18
project/application/src/app/modules/not-found/not-found.component.ts
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,18 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { HttpResponseStatusService } from '../core/services/http-response-status/http-response-status.service'; | ||
|
||
@Component({ | ||
selector: 'app-not-found', | ||
templateUrl: './not-found.component.html', | ||
styleUrls: ['./not-found.component.css'], | ||
}) | ||
export class NotFoundComponent implements OnInit { | ||
title = 'Not found page!'; | ||
|
||
constructor(private httpResponseStatusService: HttpResponseStatusService) {} | ||
|
||
ngOnInit() { | ||
this.httpResponseStatusService.setStatus(404, 'Not Found'); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
project/application/src/app/modules/not-found/not-found.module.ts
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,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { NotFoundComponent } from './not-found.component'; | ||
import { NotFoundRoutingModule } from './not-found-routing.module'; | ||
|
||
@NgModule({ | ||
imports: [NotFoundRoutingModule], | ||
declarations: [NotFoundComponent], | ||
}) | ||
export class NotFoundModule {} |
19 changes: 19 additions & 0 deletions
19
project/application/src/app/modules/routing/routing.module.ts
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 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
|
||
export const routes: Routes = [ | ||
{ | ||
path: '', | ||
loadChildren: '../home/home.module#HomeModule', | ||
}, | ||
{ | ||
path: '**', | ||
loadChildren: '../not-found/not-found.module#NotFoundModule', | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forRoot(routes, { initialNavigation: 'enabled' })], | ||
exports: [RouterModule], | ||
}) | ||
export class RoutingModule {} |
Empty file.
Empty file.
Empty file.
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,4 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
@NgModule({}) | ||
export class SharedModule {} |
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