Skip to content

Commit

Permalink
refactor: precalculate index path
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevMinerTV committed Sep 28, 2023
1 parent f328313 commit 244f067
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func main() {
log.Printf("Invalid compression level")
}

index := filepath.Join(*fFilePath, *fIndex)

app := fiber.New(fiber.Config{
GETOnly: true,
EnablePrintRoutes: true,
Expand All @@ -56,23 +58,22 @@ func main() {
}

if *fSPA {
log.Printf("Serving files from %s as SPA", *fFilePath)
log.Printf("Serving files from %s as SPA with index file %s", *fFilePath, index)
} else {
log.Printf("Serving files from %s", *fFilePath)
log.Printf("Serving files from %s with index file %s", *fFilePath, index)
}

app.Static("/", *fFilePath, fiber.Static{
Compress: true,
Browse: false,
Download: false,
CacheDuration: *fCacheDuration,
Index: *fIndex,
MaxAge: int((*fCacheDuration).Seconds()),
})

if *fSPA {
app.Use(func(c *fiber.Ctx) error {
return c.SendFile(filepath.Join(*fFilePath, *fIndex))
log.Printf("Serving index.html for %s", c.Path())
return c.SendFile(index)
})
}

Expand Down

0 comments on commit 244f067

Please sign in to comment.