mirror of
https://github.com/ghostersk/gowebmail.git
synced 2026-06-15 15:09:39 +01:00
add embed package and set it up
This commit is contained in:
+16
-2
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ghostersk/gowebmail"
|
||||||
"github.com/ghostersk/gowebmail/config"
|
"github.com/ghostersk/gowebmail/config"
|
||||||
"github.com/ghostersk/gowebmail/internal/db"
|
"github.com/ghostersk/gowebmail/internal/db"
|
||||||
"github.com/ghostersk/gowebmail/internal/handlers"
|
"github.com/ghostersk/gowebmail/internal/handlers"
|
||||||
@@ -52,6 +54,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Normal server startup ──────────────────────────────────────────────
|
// ── Normal server startup ──────────────────────────────────────────────
|
||||||
|
staticFS, err := fs.Sub(gowebmail.WebFS, "web/static")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("embed static fs: %v", err)
|
||||||
|
}
|
||||||
cfg, err := config.Load()
|
cfg, err := config.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("config load: %v", err)
|
log.Fatalf("config load: %v", err)
|
||||||
@@ -81,10 +87,18 @@ func main() {
|
|||||||
|
|
||||||
// Static files
|
// Static files
|
||||||
r.PathPrefix("/static/").Handler(
|
r.PathPrefix("/static/").Handler(
|
||||||
http.StripPrefix("/static/", http.FileServer(http.Dir("./web/static/"))),
|
http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))),
|
||||||
)
|
)
|
||||||
r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./web/static/img/favicon.png")
|
data, err := gowebmail.WebFS.ReadFile("web/static/img/favicon.png")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("favicon error: %v", err)
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "image/png")
|
||||||
|
w.Write(data)
|
||||||
})
|
})
|
||||||
// Public auth routes
|
// Public auth routes
|
||||||
auth := r.PathPrefix("/auth").Subrouter()
|
auth := r.PathPrefix("/auth").Subrouter()
|
||||||
|
|||||||
Reference in New Issue
Block a user