forked from gofiber/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (35 loc) · 870 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"sveltekit-embed/handler"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
)
//go:embed public/*.*
//go:embed public/*/*.*
//go:embed public/*/*/*.*
//go:embed public/*/*/*/*.*
var svelteFS embed.FS
func main() {
// Sub
publicFS, err := fs.Sub(svelteFS, "public")
if err != nil {
log.Fatal(err)
}
// Create new fiber instance
app := fiber.New()
// Main GEO handler that is cached for 10 minutes
// original code at https://github.com/gofiber/recipes/blob/master/geoip
app.Get("/:ip.json", handler.Cache(10*time.Minute), handler.GEO())
// Serve Single Page application
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(publicFS),
NotFoundFile: "index.html",
}))
// Listen on port :8080
log.Fatal(app.Listen(":8080"))
}