5
5
"log/slog"
6
6
"net/http"
7
7
"os"
8
+ "path"
8
9
9
10
"github.com/ghostrepo00/go-note/config"
10
11
"github.com/ghostrepo00/go-note/internal/pkg/model"
@@ -22,26 +23,29 @@ func NewWebServer(config *config.AppConfig) *webServer {
22
23
return & webServer {config }
23
24
}
24
25
25
- func createMyRender () multitemplate.Renderer {
26
+ func createMyRender (appConfig * config. AppConfig ) multitemplate.Renderer {
26
27
r := multitemplate .NewRenderer ()
27
- r .AddFromFiles ("index" , "web/template/shared/base.html" , "web/template/home/index.html" , "web/template/shared/error_list.html" )
28
- r .AddFromFiles ("index_partial" , "web/template/home/index.html" , "web/template/shared/error_list.html" )
29
- r .AddFromFiles ("error_list" , "web/template/shared/error_list.html" )
30
- r .AddFromFiles ("error" , "web/template/shared/base.html" , "web/template/shared/error.html" )
28
+ r .AddFromFiles ("index" ,
29
+ path .Join (appConfig .Web .BasePath , "web/template/shared/base.html" ),
30
+ path .Join (appConfig .Web .BasePath , "web/template/home/index.html" ),
31
+ path .Join (appConfig .Web .BasePath , "web/template/shared/error_list.html" ))
32
+ r .AddFromFiles ("index_partial" , path .Join (appConfig .Web .BasePath , "web/template/home/index.html" ), path .Join (appConfig .Web .BasePath , "web/template/shared/error_list.html" ))
33
+ r .AddFromFiles ("error_list" , path .Join (appConfig .Web .BasePath , "web/template/shared/error_list.html" ))
34
+ r .AddFromFiles ("error" , path .Join (appConfig .Web .BasePath , "web/template/shared/base.html" ), path .Join (appConfig .Web .BasePath , "web/template/shared/error.html" ))
31
35
return r
32
36
}
33
37
34
38
func ConfigureWebRouter (appConfig * config.AppConfig , dbClient * supabase.Client ) * gin.Engine {
35
39
router := gin .Default ()
36
- router .HTMLRender = createMyRender ()
40
+ router .HTMLRender = createMyRender (appConfig )
37
41
router .Use (cors .Default ())
38
42
router .Use (gin .CustomRecovery (func (c * gin.Context , err any ) {
39
43
slog .Error ("Unhandled exception" , "error" , err )
40
44
c .HTML (http .StatusInternalServerError , "error" , gin.H {"Status" : 500 , "Message" : "Internal Error" })
41
45
}))
42
46
43
- router .Static ("/assets" , "web/assets" )
44
- router .StaticFile ("/favicon.ico" , "web/favicon.ico" )
47
+ router .Static ("/assets" , path . Join ( appConfig . Web . BasePath , "web/assets" ) )
48
+ router .StaticFile ("/favicon.ico" , path . Join ( appConfig . Web . BasePath , "web/favicon.ico" ) )
45
49
46
50
var crypto CryptoService = NewCryptoService (os .Getenv ("CRYPTO_KEY" ), os .Getenv ("CRYPTO_IV_PAD" ))
47
51
var service AppService = NewAppService (appConfig , dbClient , crypto )
0 commit comments