add frontend (#5)

添加前端页面
This commit is contained in:
Sakurasan
2023-05-13 05:01:35 +08:00
committed by GitHub
parent 9339cab328
commit 70168fd01e
22 changed files with 2046 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"opencatd-open/router"
@@ -12,6 +14,18 @@ import (
"gorm.io/gorm"
)
//go:embed dist/*
var web embed.FS
func getFileSystem(path string) http.FileSystem {
fs, err := fs.Sub(web, path)
if err != nil {
panic(err)
}
return http.FS(fs)
}
func main() {
args := os.Args[1:]
if len(args) > 0 {
@@ -90,11 +104,17 @@ func main() {
// r.GET("/v1/models", router.HandleProy)
// r.GET("/v1/dashboard/billing/subscription", router.HandleProy)
r.GET("/", func(c *gin.Context) {
c.Writer.WriteHeader(http.StatusOK)
c.Writer.WriteString(`<h1><a href="https://github.com/mirrors2/opencatd-open" >opencatd-open</a> available</h1>Api-Keys:<a href=https://platform.openai.com/account/api-keys >https://platform.openai.com/account/api-keys</a>`)
})
// r.Use(static.Serve("/", static.LocalFile("dist", false)))
idxFS, err := fs.Sub(web, "dist")
if err != nil {
panic(err)
}
r.GET("/", gin.WrapH(http.FileServer(http.FS(idxFS))))
assetsFS, err := fs.Sub(web, "dist/assets")
if err != nil {
panic(err)
}
r.GET("/assets/*filepath", gin.WrapH(http.StripPrefix("/assets/", http.FileServer(http.FS(assetsFS)))))
if port == "" {
port = "80"
}