WIP: Docker

This commit is contained in:
aditya.chandel
2025-01-22 16:56:18 -07:00
parent 494aba24c6
commit 844b5070aa
11 changed files with 50 additions and 26 deletions
@@ -1,11 +1,12 @@
import {Injectable, inject} from '@angular/core'; import {Injectable, inject} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http'; import {HttpClient, HttpHeaders} from '@angular/common/http';
import {API_CONFIG} from '../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class FileService { export class FileService {
private readonly url = 'http://localhost:8080/v1/book'; private readonly url = `${API_CONFIG.BASE_URL}/v1/book`;
private readonly http = inject(HttpClient); private readonly http = inject(HttpClient);
downloadFile(bookId: number): void { downloadFile(bookId: number): void {
@@ -6,12 +6,13 @@ import {Library} from '../model/library.model';
import {BookService} from './book.service'; import {BookService} from './book.service';
import {SortOption} from '../model/sort.model'; import {SortOption} from '../model/sort.model';
import {LibraryState} from '../model/state/library-state.model'; import {LibraryState} from '../model/state/library-state.model';
import {API_CONFIG} from '../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class LibraryService { export class LibraryService {
private readonly url = 'http://localhost:8080/v1/library'; private readonly url = `${API_CONFIG.BASE_URL}/v1/library`;
private libraryStateSubject = new BehaviorSubject<LibraryState>({ private libraryStateSubject = new BehaviorSubject<LibraryState>({
libraries: null, libraries: null,
@@ -6,12 +6,13 @@ import { Shelf } from '../model/shelf.model';
import { SortOption } from '../model/sort.model'; import { SortOption } from '../model/sort.model';
import { BookService } from './book.service'; import { BookService } from './book.service';
import { ShelfState } from '../model/state/shelf-state.model'; import { ShelfState } from '../model/state/shelf-state.model';
import {API_CONFIG} from '../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ShelfService { export class ShelfService {
private readonly url = 'http://localhost:8080/v1/shelf'; private readonly url = `${API_CONFIG.BASE_URL}/v1/shelf`;
private shelfStateSubject = new BehaviorSubject<ShelfState>({ private shelfStateSubject = new BehaviorSubject<ShelfState>({
shelves: null, shelves: null,
loaded: false, loaded: false,
+2 -1
View File
@@ -1,3 +1,4 @@
export const API_CONFIG = { export const API_CONFIG = {
BASE_URL: 'http://localhost:8080' BASE_URL: `http://localhost:${window.location.port || 8080}`,
BROKER_URL: `ws://localhost:${window.location.port || 8080}/ws`
}; };
@@ -2,12 +2,13 @@ import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http'; import {HttpClient, HttpParams} from '@angular/common/http';
import {BehaviorSubject} from 'rxjs'; import {BehaviorSubject} from 'rxjs';
import {AppSettings} from '../model/app-settings.model'; import {AppSettings} from '../model/app-settings.model';
import {API_CONFIG} from '../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AppSettingsService { export class AppSettingsService {
private apiUrl = 'http://localhost:8080/api/settings'; private readonly apiUrl = `${API_CONFIG.BASE_URL}/api/settings`;
private appSettingsSubject = new BehaviorSubject<AppSettings | null>(null); private appSettingsSubject = new BehaviorSubject<AppSettings | null>(null);
appSettings$ = this.appSettingsSubject.asObservable(); appSettings$ = this.appSettingsSubject.asObservable();
@@ -1,12 +1,13 @@
import {inject, Injectable} from '@angular/core'; import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {API_CONFIG} from '../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class EpubService { export class EpubService {
private baseUrl = 'http://localhost:8080/api/epub'; private baseUrl = `${API_CONFIG.BASE_URL}/api/epub`;
private http = inject(HttpClient); private http = inject(HttpClient);
@@ -1,8 +1,9 @@
import { RxStompConfig } from '@stomp/rx-stomp'; import {RxStompConfig} from '@stomp/rx-stomp';
import {API_CONFIG} from '../../config/api-config';
export const rxStompConfig: RxStompConfig = { export const rxStompConfig: RxStompConfig = {
// Which server? // Which server?
brokerURL: 'ws://localhost:8080/ws', brokerURL: API_CONFIG.BROKER_URL,
// Headers // Headers
// Typical keys: login, passcode, host // Typical keys: login, passcode, host
@@ -10,6 +10,7 @@ import {Library, LibraryPath} from '../../../book/model/library.model';
import {MessageService} from 'primeng/api'; import {MessageService} from 'primeng/api';
import {DynamicDialogRef} from 'primeng/dynamicdialog'; import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {Select} from 'primeng/select'; import {Select} from 'primeng/select';
import {API_CONFIG} from '../../../config/api-config';
@Component({ @Component({
selector: 'app-book-uploader', selector: 'app-book-uploader',
@@ -26,7 +27,7 @@ import {Select} from 'primeng/select';
}) })
export class BookUploaderComponent { export class BookUploaderComponent {
private uploadUrl = 'http://localhost:8080/api/v1/files/upload'; private uploadUrl = `${API_CONFIG.BASE_URL}/api/v1/files/upload`;
private libraryService = inject(LibraryService); private libraryService = inject(LibraryService);
private messageService = inject(MessageService); private messageService = inject(MessageService);
@@ -1,13 +1,14 @@
import {inject, Injectable} from '@angular/core'; import {inject, Injectable} from '@angular/core';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http'; import {HttpClient, HttpParams} from '@angular/common/http';
import {API_CONFIG} from '../../../config/api-config';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class UtilityService { export class UtilityService {
private pathUrl = 'http://localhost:8080/v1/path'; private pathUrl = `${API_CONFIG.BASE_URL}/v1/path`;
private http = inject(HttpClient); private http = inject(HttpClient);
+2 -3
View File
@@ -2,10 +2,9 @@ version: '3.8'
services: services:
booklore-app: booklore-app:
container_name: booklore container_name: booklore
image: localhost:5000/booklore-app:v12 image: localhost:5000/booklore-app:v22
ports: ports:
- "8081:8080" - "5050:6060"
- "4201:80"
volumes: volumes:
- /Users/aditya.chandel/my-library-temp/config:/app/config - /Users/aditya.chandel/my-library-temp/config:/app/config
- /Users/aditya.chandel/my-library-temp/books:/app/books - /Users/aditya.chandel/my-library-temp/books:/app/books
+29 -13
View File
@@ -1,27 +1,43 @@
# the events block is required # the events block is required
events{} events {}
http { http {
# include the default mime.types to map file extensions to MIME types # include the default mime.types to map file extensions to MIME types
include /etc/nginx/mime.types; include /etc/nginx/mime.types;
server { server {
# set the root directory for the server (we need to copy our listen 6060; # Listen on port 6060 for both API and UI
# application files here)
# Set the root directory for the server (Angular app)
root /usr/share/nginx/html; root /usr/share/nginx/html;
# set the default index file for the server (Angular generates the # Set the default index file for the server
# index.html file for us and it will be in the above directory)
index index.html; index index.html;
# specify the configuration for the '/' location # Serve Angular UI
location / { location / {
# try to serve the requested URI. if that fails then try to try_files $uri $uri/ /index.html; # Fallback to index.html for Angular routing
# serve the URI with a trailing slash. if that fails, then }
# serve the index.html file; this is needed in order to serve
# Angular routes--e.g.,'localhost:8080/customer' will serve # Proxy API requests that start with /v1/ to the backend
# the index.html file location /v1/ {
try_files $uri $uri/ /index.html; proxy_pass http://localhost:8080; # Backend API running on port 8080
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Proxy WebSocket requests (ws://) to the backend
location /ws {
proxy_pass http://localhost:8080/ws; # Backend WebSocket endpoint
proxy_http_version 1.1; # Ensure HTTP 1.1 is used for WebSocket connection
proxy_set_header Upgrade $http_upgrade; # Pass the upgrade header
proxy_set_header Connection 'upgrade'; # Pass the connection header
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} }
} }
} }