File tree Expand file tree Collapse file tree 2 files changed +26
-18
lines changed
Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Original file line number Diff line number Diff line change 22
33public static class DotEnv
44{
5- public static void Load ( string filePath )
5+ public static void LoadEnvFile ( string fileName = ".env" )
66 {
7- if ( ! File . Exists ( filePath ) )
7+ DirectoryInfo ? dir = new DirectoryInfo ( Directory . GetCurrentDirectory ( ) ) ;
8+
9+ while ( dir != null )
810 {
9- return ;
11+ string envPath = Path . Combine ( dir . FullName , fileName ) ;
12+ if ( File . Exists ( envPath ) )
13+ {
14+ Load ( envPath ) ;
15+ return ;
16+ }
17+
18+ dir = dir . Parent ;
1019 }
1120
21+ throw new FileNotFoundException ( ".env file not found" ) ;
22+ }
23+
24+ public static void Load ( string filePath )
25+ {
1226 foreach ( string line in File . ReadAllLines ( filePath ) )
1327 {
1428 // Check if the line contains '='
@@ -31,5 +45,4 @@ public static void Load(string filePath)
3145 Environment . SetEnvironmentVariable ( key , value ) ;
3246 }
3347 }
34-
3548}
Original file line number Diff line number Diff line change 1313using OsmoDoc . API . Models ;
1414using OsmoDoc . Services ;
1515using System . IdentityModel . Tokens . Jwt ;
16+ using System . Runtime . InteropServices ;
1617
1718WebApplicationBuilder builder = WebApplication . CreateBuilder ( args ) ;
1819
2526 } ) ;
2627
2728// Load .env file
28- string root = Directory . GetCurrentDirectory ( ) ;
29- string dotenv = Path . GetFullPath ( Path . Combine ( root , ".." , ".env" ) ) ;
30- if ( File . Exists ( dotenv ) )
31- {
32- OsmoDoc . API . DotEnv . Load ( dotenv ) ;
33- }
34- else
29+ OsmoDoc . API . DotEnv . LoadEnvFile ( ) ;
30+
31+ // Initialize PDF tool path once at startup (on Windows)
32+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
3533{
36- throw new FileNotFoundException ( $ ".env file not found at path: { dotenv } ") ;
34+ OsmoDocPdfConfig . WkhtmltopdfPath = Path . Combine (
35+ builder . Environment . WebRootPath ,
36+ builder . Configuration . GetSection ( "STATIC_FILE_PATHS:HTML_TO_PDF_TOOL" ) . Value !
37+ ) ;
3738}
3839
39- // Initialize PDF tool path once at startup
40- OsmoDocPdfConfig . WkhtmltopdfPath = Path . Combine (
41- builder . Environment . WebRootPath ,
42- builder . Configuration . GetSection ( "STATIC_FILE_PATHS:HTML_TO_PDF_TOOL" ) . Value !
43- ) ;
44-
4540// Register REDIS service
4641builder . Services . AddSingleton < IConnectionMultiplexer > (
4742 ConnectionMultiplexer . Connect ( Environment . GetEnvironmentVariable ( "REDIS_URL" ) ?? throw new Exception ( "No REDIS URL specified" ) )
You can’t perform that action at this time.
0 commit comments