Skip to content

Commit 358f63e

Browse files
committed
Heroku database config and other changes for heroku (pom and aplication properties)
1 parent eff406b commit 358f63e

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

backend/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@
7676
<plugin>
7777
<groupId>org.springframework.boot</groupId>
7878
<artifactId>spring-boot-maven-plugin</artifactId>
79+
<configuration>
80+
<image>
81+
<env>
82+
<BPE_OVERRIDE_JAVA_TOOL_OPTIONS>
83+
-Xss256K
84+
-XX:ReservedCodeCacheSize=64M
85+
-XX:MaxMetaspaceSize=100000K
86+
-Xmx64M
87+
</BPE_OVERRIDE_JAVA_TOOL_OPTIONS>
88+
</env>
89+
</image>
90+
</configuration>
7991
</plugin>
8092
<plugin>
8193
<groupId>org.apache.maven.plugins</groupId>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.youdemy;
2+
3+
import com.zaxxer.hikari.HikariConfig;
4+
import com.zaxxer.hikari.HikariDataSource;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
import javax.sql.DataSource;
13+
import java.net.URI;
14+
import java.net.URISyntaxException;
15+
16+
@Configuration
17+
public class DatabaseConfig {
18+
private static Logger log = LoggerFactory.getLogger(DatabaseConfig.class);
19+
@Value("${DATABASE_URL:postgres://iyfppowuslcaqo:661b996dbc1d0774b74d7ff1daa66973d931d1a1225c06d5e97e0c47ca6542e9@ec2-52-73-155-171.compute-1.amazonaws.com:5432/d6rf3u9o1nmqk5}")
20+
private String databaseUrl;
21+
@Bean
22+
@ConditionalOnProperty("DATABASE_URL")
23+
public DataSource dataSource() throws URISyntaxException {
24+
log.info("Using database configured in DATABASE_URL=", databaseUrl);
25+
HikariConfig config = new HikariConfig();
26+
URI uri = new URI(databaseUrl);
27+
String url = "jdbc:" + new URI("postgresql", null, uri.getHost(), uri.getPort(), uri.getPath(),
28+
uri.getQuery(), uri.getFragment()).toString();
29+
String[] userInfoParts = uri.getUserInfo().split(":");
30+
String username = userInfoParts[0];
31+
String password = userInfoParts[1];
32+
config.setJdbcUrl(url);
33+
config.setUsername(username);
34+
config.setPassword(password);
35+
config.setAutoCommit(false);
36+
return new HikariDataSource(config);
37+
}
38+
}

backend/src/main/resources/application.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
spring.mustache.suffix=.html
2-
spring.datasource.url=jdbc:postgresql://${POSTGRE_IP}/${POSTGRE_DB}
3-
spring.datasource.username=${POSTGRE_USER}
4-
spring.datasource.password=${POSTGRE_PASS}
2+
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
3+
spring.datasource.driver-class-name=org.postgresql.Driver
4+
spring.datasource.username=postgres
5+
spring.datasource.password=1234
56
spring.jpa.hibernate.ddl-auto=create-drop
67
spring.datasource.hikari.auto-commit=false
78
spring.mustache.cache=false
@@ -14,7 +15,7 @@ spring.jpa.properties.hibernate.format_sql=true
1415
logging.level.org.hibernate.SQL=DEBUG
1516
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
1617

17-
server.port = 8443
18+
server.port = ${PORT:8080}
1819
server.ssl.key-store = classpath:keystore.jks
1920
server.ssl.key-store-password = password
2021
server.ssl.key-password = secret

0 commit comments

Comments
 (0)