Skip to content

Commit 12cf740

Browse files
committed
configure env variables to access from azure app service
1 parent 4b2b0bc commit 12cf740

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
package com.zaplink.ZapVerse;
22

3+
import io.github.cdimascio.dotenv.Dotenv;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import io.github.cdimascio.dotenv.Dotenv;
66

77
@SpringBootApplication
88
public class ZapVerseApplication {
99

1010
public static void main(String[] args) {
11-
Dotenv dotenv = Dotenv.load();
11+
Dotenv dotenv = null;
1212

13-
// Set system properties so Spring Boot can resolve placeholders
14-
System.setProperty("SUPABASE_DB_URL", dotenv.get("SUPABASE_DB_URL"));
15-
System.setProperty("SUPABASE_DB_USERNAME", dotenv.get("SUPABASE_DB_USERNAME"));
16-
System.setProperty("SUPABASE_DB_PASSWORD", dotenv.get("SUPABASE_DB_PASSWORD"));
13+
try {
14+
// Try loading from .env (local dev)
15+
dotenv = Dotenv.load();
16+
System.out.println("dotenv: Loaded environment variables from .env file.");
17+
} catch (Exception e) {
18+
// If .env not found, use Azure environment variables
19+
System.out.println("dotenv: .env file not found, using system environment variables.");
20+
}
21+
22+
// Set system properties (check dotenv first, then System.getenv)
23+
System.setProperty("SUPABASE_DB_URL", getenv(dotenv, "SUPABASE_DB_URL"));
24+
System.setProperty("SUPABASE_DB_USERNAME", getenv(dotenv, "SUPABASE_DB_USERNAME"));
25+
System.setProperty("SUPABASE_DB_PASSWORD", getenv(dotenv, "SUPABASE_DB_PASSWORD"));
1726

1827
SpringApplication.run(ZapVerseApplication.class, args);
1928
}
2029

21-
}
30+
private static String getenv(Dotenv dotenv, String key) {
31+
if (dotenv != null && dotenv.get(key) != null) {
32+
return dotenv.get(key);
33+
}
34+
// Azure App Service variables
35+
return System.getenv(key);
36+
}
37+
}

0 commit comments

Comments
 (0)