Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 59cbe6ba

Přidáno uživatelem Pavel Fidransky před asi 5 roky(ů)

re #33: modify backend app to load configuration from environment variables; locally loaded by docker-compose from .env file

Zobrazit rozdíly:

.gitignore
1 1
.idea
2 2
*.iml
3
.env
docker-compose.yml
15 15
    image: danekja/ymanager
16 16
    build: ./server/
17 17
    restart: always
18
    environment:
19
      - JDBC_URL
20
      - JDBC_USERNAME
21
      - JDBC_PASSWORD
22
      - JDBC_DRIVER
23
      - OAUTH2_GOOGLE_CLIENT_ID
24
      - OAUTH2_GOOGLE_CLIENT_SECRET
25
      - OAUTH2_GOOGLE_ALLOWED_DOMAINS
26
      - CORS_ALLOWED_ORIGINS
18 27
    ports:
19 28
      - 9080:8080
20 29
      - 6005:5005
example.env
1
JDBC_URL=jdbc:mariadb://db:3306/yamanager
2
JDBC_USERNAME=user
3
JDBC_PASSWORD=passwd
4
JDBC_DRIVER=org.mariadb.jdbc.Driver
5

  
6
OAUTH2_GOOGLE_CLIENT_ID=
7
OAUTH2_GOOGLE_CLIENT_SECRET=
8
OAUTH2_GOOGLE_ALLOWED_DOMAINS=
9

  
10
CORS_ALLOWED_ORIGINS=http://localhost
server/src/main/java/org/danekja/ymanager/RESTConfiguration.java
9 9
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
10 10
import com.fasterxml.jackson.databind.module.SimpleModule;
11 11
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
12
import org.springframework.beans.factory.annotation.Value;
12 13
import org.springframework.context.annotation.Bean;
13 14
import org.springframework.context.annotation.Configuration;
14 15
import org.springframework.web.servlet.config.annotation.CorsRegistry;
......
22 23

  
23 24
@Configuration
24 25
public class RESTConfiguration implements WebMvcConfigurer {
26
    @Value("${ymanager.cors.allowed-origins}")
27
    private String corsAllowedOrigins;
25 28

  
26 29
    @Override
27 30
    public void addCorsMappings(CorsRegistry registry) {
28 31
        registry.addMapping("/**")
29
                .allowedOrigins("http://localhost") //TODO replace with env variable
32
                .allowedOrigins(corsAllowedOrigins)
30 33
                .allowedMethods("GET", "POST", "PUT", "DELETE")
31 34
                .allowCredentials(true);
32 35
    }
server/src/main/resources/application.properties
1 1
server.servlet.context-path=/api
2
spring.datasource.url=jdbc:mariadb://db:3306/yamanager
3
spring.datasource.username=user
4
spring.datasource.password=passwd
5
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
2

  
3
spring.datasource.url=${JDBC_URL}
4
spring.datasource.username=${JDBC_USERNAME}
5
spring.datasource.password=${JDBC_PASSWORD}
6
spring.datasource.driver-class-name=${JDBC_DRIVER}
7

  
6 8
#populate these from your google oauth2 setup
7 9
#https://www.baeldung.com/spring-security-5-oauth2-login
8
#spring.security.oauth2.client.registration.google.client-id=<client id value here>
9
#spring.security.oauth2.client.registration.google.client-secret=<secret here>
10
spring.security.oauth2.client.registration.google.client-id=${OAUTH2_GOOGLE_CLIENT_ID}
11
spring.security.oauth2.client.registration.google.client-secret=${OAUTH2_GOOGLE_CLIENT_SECRET}
12

  
10 13
#comma-separated list of allowed domains, leave empty for all
11
#ymanager.oauth2.client.google.allowed-domains=domain.com,domain2.com
14
ymanager.oauth2.client.google.allowed-domains=${OAUTH2_GOOGLE_ALLOWED_DOMAINS}
15

  
16
#comma-separated list of allowed origins, use asterisk for all
17
ymanager.cors.allowed-origins=${CORS_ALLOWED_ORIGINS}

Také k dispozici: Unified diff