profiles #7

Merged
simponic merged 5 commits from profiles into main 2024-04-09 18:39:15 -04:00
1 changed files with 6 additions and 6 deletions
Showing only changes of commit fb85836649 - Show all commits

View File

@ -71,16 +71,11 @@ func CacheControlMiddleware(next http.Handler, maxAge int) http.Handler {
func MakeServer(argv *args.Arguments, dbConn *sql.DB) *http.Server { func MakeServer(argv *args.Arguments, dbConn *sql.DB) *http.Server {
mux := http.NewServeMux() mux := http.NewServeMux()
staticFileServer := http.FileServer(http.Dir(argv.StaticPath)) // "dependency injection"
uploadFileServer := http.FileServer(http.Dir(argv.UploadPath))
mux.Handle("GET /static/", http.StripPrefix("/static/", CacheControlMiddleware(staticFileServer, 3600)))
mux.Handle("GET /uploads/", http.StripPrefix("/uploads/", CacheControlMiddleware(uploadFileServer, 3600)))
cloudflareAdapter := &cloudflare.CloudflareExternalDNSAdapter{ cloudflareAdapter := &cloudflare.CloudflareExternalDNSAdapter{
APIToken: argv.CloudflareToken, APIToken: argv.CloudflareToken,
ZoneId: argv.CloudflareZone, ZoneId: argv.CloudflareZone,
} }
uploadAdapter := &filesystem.FilesystemAdapter{ uploadAdapter := &filesystem.FilesystemAdapter{
BasePath: argv.UploadPath, BasePath: argv.UploadPath,
Permissions: 0777, Permissions: 0777,
@ -94,6 +89,11 @@ func MakeServer(argv *args.Arguments, dbConn *sql.DB) *http.Server {
} }
} }
staticFileServer := http.FileServer(http.Dir(argv.StaticPath))
uploadFileServer := http.FileServer(http.Dir(argv.UploadPath))
mux.Handle("GET /static/", http.StripPrefix("/static/", CacheControlMiddleware(staticFileServer, 3600)))
mux.Handle("GET /uploads/", http.StripPrefix("/uploads/", CacheControlMiddleware(uploadFileServer, 3600)))
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
requestContext := makeRequestContext() requestContext := makeRequestContext()
LogRequestContinuation(requestContext, r, w)(auth.VerifySessionContinuation, FailurePassingContinuation)(IdContinuation, IdContinuation)(auth.ListUsersContinuation, auth.ListUsersContinuation)(template.TemplateContinuation("home.html", true), FailurePassingContinuation)(LogExecutionTimeContinuation, LogExecutionTimeContinuation)(IdContinuation, IdContinuation) LogRequestContinuation(requestContext, r, w)(auth.VerifySessionContinuation, FailurePassingContinuation)(IdContinuation, IdContinuation)(auth.ListUsersContinuation, auth.ListUsersContinuation)(template.TemplateContinuation("home.html", true), FailurePassingContinuation)(LogExecutionTimeContinuation, LogExecutionTimeContinuation)(IdContinuation, IdContinuation)