Fix pdf viewer when opening in docker.

Have envs for angular.
This commit is contained in:
aditya.chandel
2025-01-22 18:30:28 -07:00
parent df6d756dc5
commit 156e2439aa
9 changed files with 37 additions and 9 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ COPY ./booklore-ui/package.json ./booklore-ui/package-lock.json ./
RUN npm install RUN npm install
COPY ./booklore-ui /angular-app/ COPY ./booklore-ui /angular-app/
RUN npm run build --prod RUN npm run build --configuration=production
# Stage 2: Build the Spring Boot app with Gradle # Stage 2: Build the Spring Boot app with Gradle
FROM gradle:jdk21-alpine AS springboot-build FROM gradle:jdk21-alpine AS springboot-build
@@ -102,7 +102,7 @@ public class BooksService {
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId)); BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
byte[] pdfBytes = Files.readAllBytes(new File(FileUtils.getBookFullPath(bookEntity)).toPath()); byte[] pdfBytes = Files.readAllBytes(new File(FileUtils.getBookFullPath(bookEntity)).toPath());
return ResponseEntity.ok() return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "application/pdf") .header(HttpHeaders.CONTENT_TYPE, "text/plain")
.body(pdfBytes); .body(pdfBytes);
} }
@@ -15,7 +15,7 @@ spring:
name: booklore-api name: booklore-api
datasource: datasource:
driver-class-name: org.h2.Driver driver-class-name: org.h2.Driver
url: jdbc:h2:~/my-library-temp/config/db/booklore url: jdbc:h2:~/my-library-temp/config/local/db/booklore
username: sa username: sa
password: password password: password
jpa: jpa:
+6
View File
@@ -52,6 +52,12 @@
}, },
"configurations": { "configurations": {
"production": { "production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"budgets": [ "budgets": [
{ {
"type": "initial", "type": "initial",
+3 -4
View File
@@ -1,4 +1,3 @@
export const API_CONFIG = { import {environment} from '../../environments/environment';
BASE_URL: `http://localhost:${window.location.port || 8080}`,
BROKER_URL: `ws://localhost:${window.location.port || 8080}/ws` export const API_CONFIG = environment.API_CONFIG;
};
@@ -0,0 +1,7 @@
export const environment = {
production: true,
API_CONFIG: {
BASE_URL: `http://localhost:${window.location.port}`,
BROKER_URL: `ws://localhost:${window.location.port}/ws`,
},
};
@@ -0,0 +1,7 @@
export const environment = {
production: false,
API_CONFIG: {
BASE_URL: 'http://localhost:8080',
BROKER_URL: 'ws://localhost:8080/ws',
},
};
+2 -2
View File
@@ -2,9 +2,9 @@ version: '3.8'
services: services:
booklore-app: booklore-app:
container_name: booklore container_name: booklore
image: localhost:5000/booklore-app:v24 image: localhost:5000/booklore-app:v33
ports: ports:
- "5050:6060" - "5050:6060"
volumes: volumes:
- /Users/aditya.chandel/my-library-temp/config:/app/config - /Users/aditya.chandel/my-library-temp/config/docker:/app/config
- /Users/aditya.chandel/my-library-temp/books:/app/books - /Users/aditya.chandel/my-library-temp/books:/app/books
+9
View File
@@ -17,6 +17,15 @@ http {
# Serve Angular UI # Serve Angular UI
location / { location / {
try_files $uri $uri/ /index.html; # Fallback to index.html for Angular routing try_files $uri $uri/ /index.html; # Fallback to index.html for Angular routing
location ~* \.mjs$ {
# target only *.mjs files
# now we can safely override types since we are only
# targeting a single file extension.
types {
text/javascript mjs;
}
}
} }
# Proxy API requests that start with /api/ to the backend # Proxy API requests that start with /api/ to the backend