mirror of
https://github.com/tuxdotrs/trok.git
synced 2025-07-06 20:06:34 +05:30
feat: add website
This commit is contained in:
41
internal/server/web.go
Normal file
41
internal/server/web.go
Normal file
@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/tuxdotrs/trok/internal/web"
|
||||
)
|
||||
|
||||
type TrokWeb struct {
|
||||
app *fiber.App
|
||||
addr string
|
||||
}
|
||||
|
||||
func NewTrokWeb(addr string) *TrokWeb {
|
||||
return &TrokWeb{
|
||||
app: fiber.New(),
|
||||
addr: addr,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TrokWeb) Start() {
|
||||
t.app.Use("/", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(web.EmbedDirStatic),
|
||||
PathPrefix: "dist",
|
||||
Browse: true,
|
||||
}))
|
||||
|
||||
t.app.Use("/assets", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(web.EmbedDirStatic),
|
||||
PathPrefix: "dist/assets",
|
||||
Browse: true,
|
||||
}))
|
||||
|
||||
t.app.Listen(t.addr)
|
||||
}
|
||||
|
||||
func (t *TrokWeb) Stop() {
|
||||
t.app.Shutdown()
|
||||
}
|
Reference in New Issue
Block a user