Differenzansicht 16d-docker
im Vergleich zu 16-guards

← Zurück zur Übersicht | Demo | Quelltext auf GitHub
package.json CHANGED
@@ -7,7 +7,10 @@
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": {
7
  "build": "ng build",
8
  "watch": "ng build --watch --configuration development",
9
  "test": "ng test",
10
+ "lint": "ng lint",
11
+ "docker:build": "docker build -t book-monkey .",
12
+ "docker:build:silicon": "npm run docker:build -- --platform=linux/amd64",
13
+ "docker:redeploy": "docker compose down --remove-orphans && docker compose up -d"
14
  },
15
  "private": true,
16
  "dependencies": {
public/settings.json ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ {
2
+ "apiUrl": "https://api5.angular-buch.com"
3
+ }
public/settings.template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ {
2
+ "apiUrl": "${API_URL}"
3
+ }
src/app/shared/book-store.service.ts CHANGED
@@ -1,16 +1,18 @@
1
  import { HttpClient } from '@angular/common/http';
2
- import { Injectable } from '@angular/core';
3
  import { Observable, catchError, of } from 'rxjs';
4
 
5
  import { Book } from './book';
 
6
 
7
  @Injectable({
8
  providedIn: 'root'
9
  })
10
  export class BookStoreService {
11
- private apiUrl = 'https://api5.angular-buch.com';
12
-
13
- constructor(private http: HttpClient) {}
 
14
 
15
  getAll(): Observable<Book[]> {
16
  return this.http.get<Book[]>(`${this.apiUrl}/books`).pipe(
1
  import { HttpClient } from '@angular/common/http';
2
+ import { Inject, Injectable } from '@angular/core';
3
  import { Observable, catchError, of } from 'rxjs';
4
 
5
  import { Book } from './book';
6
+ import { API_URL } from './settings';
7
 
8
  @Injectable({
9
  providedIn: 'root'
10
  })
11
  export class BookStoreService {
12
+ constructor(
13
+ @Inject(API_URL) private apiUrl: string,
14
+ private http: HttpClient
15
+ ) {}
16
 
17
  getAll(): Observable<Book[]> {
18
  return this.http.get<Book[]>(`${this.apiUrl}/books`).pipe(
src/app/shared/settings.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ import { InjectionToken } from '@angular/core';
2
+
3
+ export interface Settings {
4
+ apiUrl: string;
5
+ }
6
+
7
+ export const API_URL = new InjectionToken<string>('apiUrl');
src/main.ts CHANGED
@@ -1,7 +1,19 @@
1
  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
 
2
  import { AppModule } from './app/app.module';
 
 
 
 
 
 
3
 
4
- platformBrowserDynamic().bootstrapModule(AppModule, {
5
- ngZoneEventCoalescing: true,
6
- })
7
- .catch(err => console.error(err));
 
 
 
 
 
1
  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2
+
3
  import { AppModule } from './app/app.module';
4
+ import { API_URL, Settings } from './app/shared/settings';
5
+
6
+ async function loadSettings(): Promise<Settings> {
7
+ const response = await fetch('settings.json');
8
+ return response.json();
9
+ }
10
 
11
+ loadSettings().then(settings => {
12
+ platformBrowserDynamic([
13
+ { provide: API_URL, useValue: settings.apiUrl }
14
+ ])
15
+ .bootstrapModule(AppModule, {
16
+ ngZoneEventCoalescing: true
17
+ })
18
+ .catch(err => console.error(err));
19
+ });