Skip to content

Commit 7348fb3

Browse files
fix: Fly and gradle build issues
* fix: Fixed compile issues and gradle configuration * fix: Fixed fly json warning * fix: Added missing Javalin dependency * fix: Updated word-wrap * fix: Added descriptive warning for failed database connections.
1 parent dbb5c43 commit 7348fb3

File tree

5 files changed

+51
-41
lines changed

5 files changed

+51
-41
lines changed

backend/build.gradle

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,42 @@ plugins {
1717
}
1818

1919
repositories {
20-
// Use jcenter for resolving your dependencies.
21-
// You can declare any Maven/Ivy/file repository here.
22-
jcenter()
20+
mavenCentral()
2321
}
2422

2523
dependencies {
2624
// This dependency is found on compile classpath of this component and consumers.
2725
implementation 'com.google.guava:guava:27.0.1-jre'
2826

2927
// Javalin is a server/networking library for Java.
30-
compile 'io.javalin:javalin:5.6.1'
31-
compile 'org.slf4j:slf4j-simple:1.7.30'
32-
compile 'org.json:json:20190722'
33-
compile 'com.j2html:j2html:1.4.0'
34-
compile 'com.fasterxml.jackson.core:jackson-databind:2.10.1'
28+
implementation 'io.javalin:javalin:5.6.1'
29+
implementation 'io.javalin:javalin-bundle:5.6.1'
30+
implementation 'org.slf4j:slf4j-simple:1.7.30'
31+
implementation 'org.json:json:20190722'
32+
implementation 'com.j2html:j2html:1.4.0'
33+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.1'
3534

3635
// PostgresSQL driver
37-
compile 'org.postgresql:postgresql:42.2.5'
36+
implementation 'org.postgresql:postgresql:42.2.5'
3837

3938
// Apache Commons Lang
40-
compile 'org.apache.commons:commons-lang3:3.0'
39+
implementation 'org.apache.commons:commons-lang3:3.0'
4140

4241
// Use JUnit test framework
4342
testImplementation 'junit:junit:4.12'
44-
implementation 'junit:junit:4.12'
4543
}
4644

47-
jar {
48-
from {
49-
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
50-
}
51-
manifest {
52-
attributes(
53-
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
54-
'Main-Class': 'server.SecretHitlerServer',
55-
'Implementation-Title': 'secret-hitler-online'
56-
)
57-
}
45+
tasks.named('test') {
46+
useJUnitPlatform()
47+
}
48+
49+
tasks.named('jar') {
50+
manifest {
51+
attributes(
52+
'Main-Class': 'server.SecretHitlerServer',
53+
'Implementation-Title': 'secret-hitler-online'
54+
)
55+
}
5856
}
5957

6058
javadoc {

backend/fly.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ processes = []
88
[env]
99

1010
[build.args]
11-
PORT = 8080
11+
PORT = "8080"
1212

1313
[experimental]
1414
allowed_public_ports = []
1515
auto_rollback = true
1616

1717
[[services]]
18-
http_checks = []
18+
http_checks = []
1919
internal_port = 8080
2020
processes = ["app"]
2121
protocol = "tcp"

backend/gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#Sat Apr 25 14:00:58 PDT 2020
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
1+
#Fri Jul 21 17:42:34 PDT 2023
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
33
distributionBase=GRADLE_USER_HOME
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists

backend/src/main/java/server/SecretHitlerServer.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public class SecretHitlerServer {
2525
// TODO: Replace this with an environment variable or environment flag
2626
private static boolean DEBUG = false;
2727
public static final int DEFAULT_PORT_NUMBER = 4040;
28-
28+
2929
// Environmental Variable Names
30+
private static final String ENV_DEBUG = "DEBUG";
3031
private static final String ENV_DATABASE_URL = "DATABASE_URL";
3132

3233
// Passed to server
@@ -73,7 +74,7 @@ public class SecretHitlerServer {
7374

7475
public static final String COMMAND_END_TERM = "end-term";
7576

76-
private static final String CODE_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTWXYZ"; // u,v character can look ambiguous
77+
private static final String CODE_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTWXYZ"; // u,v characters can look ambiguous
7778
private static final int CODE_LENGTH = 4;
7879

7980
private static final float UPDATE_FREQUENCY_MIN = 1;
@@ -89,7 +90,7 @@ public class SecretHitlerServer {
8990

9091
// </editor-fold>
9192

92-
////// Private Classes
93+
////// Private Methods
9394

9495
private static int getHerokuAssignedPort() {
9596
if (DEBUG) {
@@ -110,11 +111,17 @@ public static void main(String[] args) {
110111

111112
// Only initialize Javalin communication after the database has been queried.
112113
Javalin serverApp = Javalin.create(config -> {
113-
if (DEBUG) {
114-
config.enableCorsForAllOrigins();
115-
} else {
116-
config.enableCorsForOrigin("https://secret-hitler.online");
117-
}
114+
config.plugins.enableCors(cors -> {
115+
if (DEBUG) {
116+
cors.add(it -> {
117+
it.anyHost();
118+
});
119+
} else {
120+
cors.add(it -> {
121+
it.allowHost("https://secret-hitler.online");
122+
});
123+
}
124+
});
118125
}).start(getHerokuAssignedPort());
119126

120127
serverApp.get("/check-login", SecretHitlerServer::checkLogin); // Checks if a login is valid.
@@ -204,7 +211,12 @@ private static Connection getDatabaseConnection() {
204211
if (DEBUG) {
205212
databaseUri = new URI("");
206213
} else {
207-
databaseUri = new URI(System.getenv(ENV_DATABASE_URL));
214+
String envUri = System.getenv(ENV_DATABASE_URL);
215+
if (envUri == null) {
216+
System.out.println("Could not connect to database: No ENV_DATABASE_URL environment variable provided.");
217+
return null;
218+
}
219+
databaseUri = new URI(envUri);
208220
}
209221
String username = databaseUri.getUserInfo().split(":")[0];
210222
String password = databaseUri.getUserInfo().split(":")[1];

frontend/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)