Project can now be compiled into one file
This commit is contained in:
parent
b073b2cdb2
commit
6e495de6dd
2 changed files with 42 additions and 3 deletions
12
main.go
12
main.go
|
@ -3,8 +3,18 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.shadowhosting.xyz/shadow/cmd"
|
import (
|
||||||
|
"embed"
|
||||||
|
"git.shadowhosting.xyz/shadow/cmd"
|
||||||
|
"git.shadowhosting.xyz/shadow/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed dist/*
|
||||||
|
var distFiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
utils.DistFiles = distFiles
|
||||||
|
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,45 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/earlydata"
|
"github.com/gofiber/fiber/v2/middleware/earlydata"
|
||||||
"github.com/gofiber/fiber/v2/middleware/etag"
|
"github.com/gofiber/fiber/v2/middleware/etag"
|
||||||
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
"github.com/gofiber/fiber/v2/middleware/healthcheck"
|
"github.com/gofiber/fiber/v2/middleware/healthcheck"
|
||||||
"github.com/gofiber/fiber/v2/middleware/helmet"
|
"github.com/gofiber/fiber/v2/middleware/helmet"
|
||||||
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
||||||
"github.com/gofiber/fiber/v2/middleware/limiter"
|
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||||
"github.com/gofiber/template/html/v2"
|
"github.com/gofiber/template/html/v2"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var DistFiles embed.FS
|
||||||
|
|
||||||
|
var distFS *fs.FS
|
||||||
|
|
||||||
func Webserver() {
|
func Webserver() {
|
||||||
|
|
||||||
engine := html.New("./dist", ".html")
|
var engine *html.Engine
|
||||||
|
|
||||||
|
if !viper.GetBool("dev") {
|
||||||
|
|
||||||
|
subFS, err := fs.Sub(DistFiles, "dist")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
distFS = &subFS
|
||||||
|
|
||||||
|
engine = html.NewFileSystem(http.FS(*distFS), ".html")
|
||||||
|
} else {
|
||||||
|
engine = html.New("./dist", ".html")
|
||||||
|
}
|
||||||
|
|
||||||
if viper.GetBool("dev") {
|
if viper.GetBool("dev") {
|
||||||
engine.Reload(true)
|
engine.Reload(true)
|
||||||
|
@ -55,8 +76,16 @@ func Webserver() {
|
||||||
LimiterMiddleware: limiter.SlidingWindow{},
|
LimiterMiddleware: limiter.SlidingWindow{},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
if !viper.GetBool("dev") {
|
||||||
|
app.Use("/assets", filesystem.New(filesystem.Config{
|
||||||
|
Root: http.FS(*distFS),
|
||||||
|
PathPrefix: "assets",
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
app.Static("/assets", "./dist/assets")
|
app.Static("/assets", "./dist/assets")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
app.Get("/", func(ctx *fiber.Ctx) error {
|
app.Get("/", func(ctx *fiber.Ctx) error {
|
||||||
return ctx.Render("views/index", fiber.Map{})
|
return ctx.Render("views/index", fiber.Map{})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue