Compare commits

..

11 Commits

7 changed files with 26 additions and 16 deletions

View File

@ -20,7 +20,7 @@ COPY eeg_frontend/openapi.yaml ./
RUN npx openapi-generator-cli generate -i ./openapi.yaml -g typescript-angular -o ./src/app/api RUN npx openapi-generator-cli generate -i ./openapi.yaml -g typescript-angular -o ./src/app/api
COPY eeg_frontend/ ./ COPY eeg_frontend/ ./
RUN npm run build -- --configuration production RUN npm run build -- --configuration staging
# ---- Stage 2: Build Spring Boot Backend ---- # ---- Stage 2: Build Spring Boot Backend ----
FROM maven:3.9-eclipse-temurin-21 AS backend-build FROM maven:3.9-eclipse-temurin-21 AS backend-build
@ -65,12 +65,8 @@ USER eeg
EXPOSE 8080 EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
ENTRYPOINT ["java", \ ENTRYPOINT ["java", \
"-XX:+UseContainerSupport", \ "-XX:+UseContainerSupport", \
"-XX:MaxRAMPercentage=75.0", \ "-XX:MaxRAMPercentage=75.0", \
"-Djava.security.egd=file:/dev/./urandom", \ "-Djava.security.egd=file:/dev/./urandom", \
"-jar", "app.jar", \ "-jar", "app.jar"]
"--spring.profiles.active=prod"]

View File

@ -28,4 +28,4 @@ foreach ($f in $Files) {
"`n" | Out-File -Append $OutFile -Encoding UTF8 "`n" | Out-File -Append $OutFile -Encoding UTF8
} }
Write-Host "Erfolgreich! Der Kontext für Backend und Frontend wurde in '$OutFile' gespeichert." Write-Host "Erfolgreich! Der Kontext für Backend und Frontend wurde in '$OutFile' gespeichert.."

View File

@ -23,6 +23,7 @@ import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
import org.springframework.security.oauth2.jwt.NimbusJwtEncoder; import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
import org.springframework.security.oauth2.server.resource.web.HeaderBearerTokenResolver;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.CorsConfigurationSource;
@ -30,7 +31,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@ -62,6 +62,7 @@ public class SecurityConfig {
.anyRequest().denyAll() .anyRequest().denyAll()
) )
.oauth2ResourceServer(oauth2 -> oauth2 .oauth2ResourceServer(oauth2 -> oauth2
.bearerTokenResolver(new HeaderBearerTokenResolver("X-Access-Token"))
.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())) .jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter()))
); );
@ -94,7 +95,7 @@ public class SecurityConfig {
CorsConfiguration configuration = new CorsConfiguration(); CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.stream(corsOrigins.split(",")).map(String::trim).toList()); configuration.setAllowedOrigins(Arrays.stream(corsOrigins.split(",")).map(String::trim).toList());
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type")); configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Access-Token"));
configuration.setAllowCredentials(true); configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration); source.registerCorsConfiguration("/**", configuration);

View File

@ -12,7 +12,7 @@ spring:
jwt: jwt:
secret: dev-only-secret-do-not-use-in-production-2025 secret: dev-only-secret-do-not-use-in-production-2025
app: app:
cors-origins: http://localhost:4200 cors-origins: http://localhost:4200,https://preview.coolify.mueller-dev.com
eda: eda:
simulation: simulation:
consent-delay-ms: 3000 consent-delay-ms: 3000

View File

@ -48,6 +48,15 @@
], ],
"outputHashing": "all" "outputHashing": "all"
}, },
"staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
],
"outputHashing": "all"
},
"development": { "development": {
"optimization": false, "optimization": false,
"extractLicenses": false, "extractLicenses": false,
@ -62,6 +71,9 @@
"production": { "production": {
"buildTarget": "eeg_frontend:build:production" "buildTarget": "eeg_frontend:build:production"
}, },
"staging": {
"buildTarget": "eeg_frontend:build:staging"
},
"development": { "development": {
"buildTarget": "eeg_frontend:build:development" "buildTarget": "eeg_frontend:build:development"
} }

View File

@ -3,14 +3,11 @@ import {HttpInterceptorFn} from '@angular/common/http';
export const jwtInterceptor: HttpInterceptorFn = (req, next) => { export const jwtInterceptor: HttpInterceptorFn = (req, next) => {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
// If a token exists, clone the request and add the Authorization header
if (token) { if (token) {
const clonedRequest = req.clone({ const authReq = req.clone({
setHeaders: { headers: req.headers.set('X-Access-Token', token)
Authorization: `Bearer ${token}`
}
}); });
return next(clonedRequest); return next(authReq);
} }
return next(req); return next(req);

View File

@ -0,0 +1,4 @@
export const environment = {
production: false,
apiUrl: 'https://preview.coolify.mueller-dev.com'
};