Differenzansicht 16f-ssr
im Vergleich zu 16-guards

← Zurück zur Ãœbersicht | Demo | Quelltext auf GitHub
angular.json CHANGED
@@ -37,7 +37,15 @@
37
  "styles": [
38
  "src/styles.css"
39
  ],
40
- "scripts": []
 
 
 
 
 
 
 
 
41
  },
42
  "configurations": {
43
  "production": {
37
  "styles": [
38
  "src/styles.css"
39
  ],
40
+ "scripts": [],
41
+ "server": "src/main.server.ts",
42
+ "prerender": {
43
+ "discoverRoutes": false,
44
+ "routesFile": "routes.txt"
45
+ },
46
+ "ssr": {
47
+ "entry": "server.ts"
48
+ }
49
  },
50
  "configurations": {
51
  "production": {
package.json CHANGED
@@ -7,7 +7,8 @@
7
  "build": "ng build",
8
  "watch": "ng build --watch --configuration development",
9
  "test": "ng test",
10
- "lint": "ng lint"
 
11
  },
12
  "private": true,
13
  "dependencies": {
@@ -18,9 +19,12 @@
18
  "@angular/forms": "^17.3.0",
19
  "@angular/platform-browser": "^17.3.0",
20
  "@angular/platform-browser-dynamic": "^17.3.0",
 
21
  "@angular/router": "^17.3.0",
 
22
  "angular-date-value-accessor": "^3.0.0",
23
  "book-monkey5-styles": "^1.0.4",
 
24
  "rxjs": "~7.8.0",
25
  "tslib": "^2.3.0",
26
  "zone.js": "~0.14.3"
@@ -34,7 +38,9 @@
34
  "@angular-eslint/template-parser": "17.3.0",
35
  "@angular/cli": "^17.3.6",
36
  "@angular/compiler-cli": "^17.3.0",
 
37
  "@types/jasmine": "~5.1.0",
 
38
  "@typescript-eslint/eslint-plugin": "7.2.0",
39
  "@typescript-eslint/parser": "7.2.0",
40
  "eslint": "^8.57.0",
@@ -46,4 +52,4 @@
46
  "karma-jasmine-html-reporter": "~2.1.0",
47
  "typescript": "~5.4.2"
48
  }
49
- }
7
  "build": "ng build",
8
  "watch": "ng build --watch --configuration development",
9
  "test": "ng test",
10
+ "lint": "ng lint",
11
+ "serve:ssr:book-monkey": "node dist/book-monkey/server/server.mjs"
12
  },
13
  "private": true,
14
  "dependencies": {
19
  "@angular/forms": "^17.3.0",
20
  "@angular/platform-browser": "^17.3.0",
21
  "@angular/platform-browser-dynamic": "^17.3.0",
22
+ "@angular/platform-server": "^17.3.0",
23
  "@angular/router": "^17.3.0",
24
+ "@angular/ssr": "^17.3.6",
25
  "angular-date-value-accessor": "^3.0.0",
26
  "book-monkey5-styles": "^1.0.4",
27
+ "express": "^4.18.2",
28
  "rxjs": "~7.8.0",
29
  "tslib": "^2.3.0",
30
  "zone.js": "~0.14.3"
38
  "@angular-eslint/template-parser": "17.3.0",
39
  "@angular/cli": "^17.3.6",
40
  "@angular/compiler-cli": "^17.3.0",
41
+ "@types/express": "^4.17.17",
42
  "@types/jasmine": "~5.1.0",
43
+ "@types/node": "^18.18.0",
44
  "@typescript-eslint/eslint-plugin": "7.2.0",
45
  "@typescript-eslint/parser": "7.2.0",
46
  "eslint": "^8.57.0",
52
  "karma-jasmine-html-reporter": "~2.1.0",
53
  "typescript": "~5.4.2"
54
  }
55
+ }
routes.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ /
2
+ /home
3
+ /books
4
+ /books/9783864909467
5
+ /books/9783864907791
6
+ /books/9783864906466
7
+ /books/9783864903571
server.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { APP_BASE_HREF } from '@angular/common';
2
+ import { CommonEngine } from '@angular/ssr';
3
+ import express from 'express';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import AppServerModule from './src/main.server';
7
+
8
+ // The Express app is exported so that it can be used by serverless Functions.
9
+ export function app(): express.Express {
10
+ const server = express();
11
+ const serverDistFolder = dirname(fileURLToPath(import.meta.url));
12
+ const browserDistFolder = resolve(serverDistFolder, '../browser');
13
+ const indexHtml = join(serverDistFolder, 'index.server.html');
14
+
15
+ const commonEngine = new CommonEngine();
16
+
17
+ server.set('view engine', 'html');
18
+ server.set('views', browserDistFolder);
19
+
20
+ // Example Express Rest API endpoints
21
+ // server.get('/api/**', (req, res) => { });
22
+ // Serve static files from /browser
23
+ server.get('*.*', express.static(browserDistFolder, {
24
+ maxAge: '1y'
25
+ }));
26
+
27
+ // All regular routes use the Angular engine
28
+ server.get('*', (req, res, next) => {
29
+ const { protocol, originalUrl, baseUrl, headers } = req;
30
+
31
+ commonEngine
32
+ .render({
33
+ bootstrap: AppServerModule,
34
+ documentFilePath: indexHtml,
35
+ url: `${protocol}://${headers.host}${originalUrl}`,
36
+ publicPath: browserDistFolder,
37
+ providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
38
+ })
39
+ .then((html) => res.send(html))
40
+ .catch((err) => next(err));
41
+ });
42
+
43
+ return server;
44
+ }
45
+
46
+ function run(): void {
47
+ const port = process.env['PORT'] || 4000;
48
+
49
+ // Start up the Node server
50
+ const server = app();
51
+ server.listen(port, () => {
52
+ console.log(`Node Express server listening on http://localhost:${port}`);
53
+ });
54
+ }
55
+
56
+ run();
src/app/admin/book-create/book-create.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { BookCreateComponent } from './book-create.component';
4
+
5
+ describe('BookCreateComponent', () => {
6
+ let component: BookCreateComponent;
7
+ let fixture: ComponentFixture<BookCreateComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ BookCreateComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(BookCreateComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/admin/book-edit/book-edit.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { BookEditComponent } from './book-edit.component';
4
+
5
+ describe('BookEditComponent', () => {
6
+ let component: BookEditComponent;
7
+ let fixture: ComponentFixture<BookEditComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ BookEditComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(BookEditComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/admin/book-form/book-form.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { BookFormComponent } from './book-form.component';
4
+
5
+ describe('BookFormComponent', () => {
6
+ let component: BookFormComponent;
7
+ let fixture: ComponentFixture<BookFormComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ BookFormComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(BookFormComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/admin/form-errors/form-errors.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { FormErrorsComponent } from './form-errors.component';
4
+
5
+ describe('FormErrorsComponent', () => {
6
+ let component: FormErrorsComponent;
7
+ let fixture: ComponentFixture<FormErrorsComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ FormErrorsComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(FormErrorsComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/admin/shared/async-validators.service.spec.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { AsyncValidatorsService } from './async-validators.service';
4
+
5
+ describe('AsyncValidatorsService', () => {
6
+ let service: AsyncValidatorsService;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(AsyncValidatorsService);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
src/app/app.module.server.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NgModule } from '@angular/core';
2
+ import { ServerModule } from '@angular/platform-server';
3
+
4
+ import { AppModule } from './app.module';
5
+ import { AppComponent } from './app.component';
6
+
7
+ @NgModule({
8
+ imports: [
9
+ AppModule,
10
+ ServerModule,
11
+ ],
12
+ bootstrap: [AppComponent],
13
+ })
14
+ export class AppServerModule {}
src/app/app.module.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { NgModule } from '@angular/core';
2
  import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
3
- import { BrowserModule } from '@angular/platform-browser';
4
 
5
  import { AppRoutingModule } from './app-routing.module';
6
  import { AppComponent } from './app.component';
@@ -24,7 +24,8 @@ import { AuthInterceptor } from './shared/auth.interceptor';
24
  provide: HTTP_INTERCEPTORS,
25
  useClass: AuthInterceptor,
26
  multi: true
27
- }
 
28
  ],
29
  bootstrap: [AppComponent]
30
  })
1
  import { NgModule } from '@angular/core';
2
  import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
3
+ import { BrowserModule, provideClientHydration } from '@angular/platform-browser';
4
 
5
  import { AppRoutingModule } from './app-routing.module';
6
  import { AppComponent } from './app.component';
24
  provide: HTTP_INTERCEPTORS,
25
  useClass: AuthInterceptor,
26
  multi: true
27
+ },
28
+ provideClientHydration()
29
  ],
30
  bootstrap: [AppComponent]
31
  })
src/app/books/book-details/book-details.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { BookDetailsComponent } from './book-details.component';
4
+
5
+ describe('BookDetailsComponent', () => {
6
+ let component: BookDetailsComponent;
7
+ let fixture: ComponentFixture<BookDetailsComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ BookDetailsComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(BookDetailsComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/books/book-list/book-list.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { BookListComponent } from './book-list.component';
4
+
5
+ describe('BookListComponent', () => {
6
+ let component: BookListComponent;
7
+ let fixture: ComponentFixture<BookListComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ BookListComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(BookListComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/books/shared/loggedin-only.directive.spec.ts ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ import { LoggedinOnlyDirective } from './loggedin-only.directive';
2
+
3
+ describe('LoggedinOnlyDirective', () => {
4
+ it('should create an instance', () => {
5
+ const directive = new LoggedinOnlyDirective();
6
+ expect(directive).toBeTruthy();
7
+ });
8
+ });
src/app/home/home.component.spec.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { NO_ERRORS_SCHEMA } from '@angular/core';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
 
4
  import { HomeComponent } from './home.component';
@@ -9,8 +8,7 @@ describe('HomeComponent', () => {
9
 
10
  beforeEach(async () => {
11
  await TestBed.configureTestingModule({
12
- declarations: [ HomeComponent ],
13
- schemas: [NO_ERRORS_SCHEMA]
14
  })
15
  .compileComponents();
16
 
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
 
3
  import { HomeComponent } from './home.component';
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
+ declarations: [ HomeComponent ]
 
12
  })
13
  .compileComponents();
14
 
src/app/search/search.component.spec.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { SearchComponent } from './search.component';
4
+
5
+ describe('SearchComponent', () => {
6
+ let component: SearchComponent;
7
+ let fixture: ComponentFixture<SearchComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ SearchComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(SearchComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
src/app/shared/book-store.service.spec.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { BookStoreService } from './book-store.service';
4
+
5
+ describe('BookStoreService', () => {
6
+ let service: BookStoreService;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(BookStoreService);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
src/main.server.ts ADDED
@@ -0,0 +1 @@
 
1
+ export { AppServerModule as default } from './app/app.module.server';
tsconfig.app.json CHANGED
@@ -3,10 +3,14 @@
3
  "extends": "./tsconfig.json",
4
  "compilerOptions": {
5
  "outDir": "./out-tsc/app",
6
- "types": []
 
 
7
  },
8
  "files": [
9
- "src/main.ts"
 
 
10
  ],
11
  "include": [
12
  "src/**/*.d.ts"
3
  "extends": "./tsconfig.json",
4
  "compilerOptions": {
5
  "outDir": "./out-tsc/app",
6
+ "types": [
7
+ "node"
8
+ ]
9
  },
10
  "files": [
11
+ "src/main.ts",
12
+ "src/main.server.ts",
13
+ "server.ts"
14
  ],
15
  "include": [
16
  "src/**/*.d.ts"