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

View File

@@ -7,7 +7,7 @@ COPY ./booklore-ui/package.json ./booklore-ui/package-lock.json ./
RUN npm install
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
FROM gradle:jdk21-alpine AS springboot-build

View File

@@ -102,7 +102,7 @@ public class BooksService {
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
byte[] pdfBytes = Files.readAllBytes(new File(FileUtils.getBookFullPath(bookEntity)).toPath());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "application/pdf")
.header(HttpHeaders.CONTENT_TYPE, "text/plain")
.body(pdfBytes);
}

View File

@@ -15,7 +15,7 @@ spring:
name: booklore-api
datasource:
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
password: password
jpa:

View File

@@ -52,6 +52,12 @@
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",

View File

@@ -1,4 +1,3 @@
export const API_CONFIG = {
BASE_URL: `http://localhost:${window.location.port || 8080}`,
BROKER_URL: `ws://localhost:${window.location.port || 8080}/ws`
};
import {environment} from '../../environments/environment';
export const API_CONFIG = environment.API_CONFIG;

View File

@@ -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`,
},
};

View File

@@ -0,0 +1,7 @@
export const environment = {
production: false,
API_CONFIG: {
BASE_URL: 'http://localhost:8080',
BROKER_URL: 'ws://localhost:8080/ws',
},
};

View File

@@ -2,9 +2,9 @@ version: '3.8'
services:
booklore-app:
container_name: booklore
image: localhost:5000/booklore-app:v24
image: localhost:5000/booklore-app:v33
ports:
- "5050:6060"
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

View File

@@ -17,6 +17,15 @@ http {
# Serve Angular UI
location / {
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