diff --git a/docker-compose.yml b/docker-compose.yml index e99d135..60fd69e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,8 +21,6 @@ services: depends_on: - "db" restart: always - ports: - - "8080:8080" frontend: build: context: ./frontend @@ -35,12 +33,4 @@ services: ports: - "4200:80" environment: - # change this env-variable in prod - BACKEND_URL: http://backend/ - # alternative way manipulate the api.json: - #{ - # "api": "http://backend/" - #} - # bind-mount it read-only via: - #volumes: - # - ./api.json:/usr/share/nginx/html/assets/api.json:ro \ No newline at end of file + BACKEND_URL: http://backend:8080 diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 74b2d77..42b334f 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -12,7 +12,12 @@ RUN apt-get update RUN apt-get upgrade -y RUN apt-get install iputils-ping -y COPY --from=build /app/dist/frontend /usr/share/nginx/html -COPY nginx.conf /etc/nginx/nginx.conf +COPY nginx.conf.template /etc/nginx/nginx.conf.template +COPY docker-entrypoint.sh /app-entrypoint.sh + +RUN chmod +x /app-entrypoint.sh + +ENTRYPOINT [ "/app-entrypoint.sh" ] EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/docker-entrypoint.sh b/frontend/docker-entrypoint.sh new file mode 100644 index 0000000..ced70a9 --- /dev/null +++ b/frontend/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd /etc/nginx/ +envsubst '$BACKEND_URL' < nginx.conf.template > nginx.conf +exec "$@" diff --git a/frontend/nginx.conf b/frontend/nginx.conf.template similarity index 96% rename from frontend/nginx.conf rename to frontend/nginx.conf.template index 79fabd8..69925b9 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf.template @@ -34,7 +34,7 @@ http { add_header "Access-Control-Allow-Headers" 'X-Requested-With,Accept,Content-Type, Origin'; location /api { - proxy_pass http://backend/; + proxy_pass ${BACKEND_URL}; add_header "Access-Control-Allow-Origin" "*"; add_header "Access-Control-Allow-Methods" 'GET, POST, OPTIONS, PUT, DELETE'; add_header "Access-Control-Allow-Headers" 'X-Requested-With,Accept,Content-Type, Origin'; diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 780c6bf..24254ec 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -6,7 +6,7 @@ import { AppComponent } from './app.component'; import {LoginComponent} from "./auth/login/login.component"; import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import {HttpClient, HttpClientModule, HttpHandler} from "@angular/common/http"; -import {ApiModule, Configuration} from "../api"; +import {ApiModule, Configuration, ConfigurationParameters} from "../api"; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import {MatToolbarModule} from "@angular/material/toolbar"; import {MatIconModule} from "@angular/material/icon"; @@ -180,7 +180,7 @@ import { DraggableSchedulerComponent } from './schedules/draggable-scheduler/dra // context "API_TOKEN": authService.getAccessToken.bind(authService) }, - //basePath: environment.api + basePath: environment.api, } ), deps: [AuthService], diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index bf9fcf4..43c1478 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - api: "api" + api: "http://localhost:8080/api" }; /*