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
|
||||
|
||||
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() {
|
||||
|
||||
utils.DistFiles = distFiles
|
||||
|
||||
cmd.Execute()
|
||||
}
|
||||
|
|
|
@ -1,24 +1,45 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/earlydata"
|
||||
"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/helmet"
|
||||
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
||||
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||
"github.com/gofiber/template/html/v2"
|
||||
"github.com/spf13/viper"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var DistFiles embed.FS
|
||||
|
||||
var distFS *fs.FS
|
||||
|
||||
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") {
|
||||
engine.Reload(true)
|
||||
|
@ -55,7 +76,15 @@ func Webserver() {
|
|||
LimiterMiddleware: limiter.SlidingWindow{},
|
||||
}))
|
||||
|
||||
app.Static("/assets", "./dist/assets")
|
||||
if !viper.GetBool("dev") {
|
||||
app.Use("/assets", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(*distFS),
|
||||
PathPrefix: "assets",
|
||||
}))
|
||||
} else {
|
||||
app.Static("/assets", "./dist/assets")
|
||||
|
||||
}
|
||||
|
||||
app.Get("/", func(ctx *fiber.Ctx) error {
|
||||
return ctx.Render("views/index", fiber.Map{})
|
||||
|
|
Loading…
Reference in a new issue