Skip to content

Commit

Permalink
fix: pattern dist/*: no matching files found
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloaix committed Nov 13, 2021
1 parent a589731 commit 16c28d4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion gofi-backend/env/default.go
Expand Up @@ -3,5 +3,9 @@

package env

import embed "embed"

//current 当前模式
const current = Development
const current = Development

var EmbedStaticAssets embed.FS
5 changes: 5 additions & 0 deletions gofi-backend/env/preview.go
Expand Up @@ -2,4 +2,9 @@

package env

import embed "embed"

const current = Preview

//go:embed dist/*
var EmbedStaticAssets embed.FS
5 changes: 5 additions & 0 deletions gofi-backend/env/production.go
Expand Up @@ -2,4 +2,9 @@

package env

import embed "embed"

const current = Production

//go:embed dist/*
var EmbedStaticAssets embed.FS
25 changes: 12 additions & 13 deletions gofi-backend/main.go
@@ -1,7 +1,6 @@
package main

import (
"embed"
"github.com/aviddiviner/gin-limit"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
Expand All @@ -14,9 +13,6 @@ import (
"net/http"
)

//go:embed dist/*
var embedStaticAssets embed.FS

func init() {
extension.BindAdditionalType()
boot.ParseArguments()
Expand All @@ -37,16 +33,19 @@ func main() {
}

app.Use(middleware.CORS)
app.Use(middleware.StaticFS("/", "dist", embedStaticAssets))

app.NoRoute(func(context *gin.Context) {
indexBytes, err := embedStaticAssets.ReadFile("dist/index.html")
if err != nil {
logrus.Fatal(err)
}
context.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
context.String(http.StatusOK, string(indexBytes))
})
if !env.IsDevelop() {
app.Use(middleware.StaticFS("/", "dist", env.EmbedStaticAssets))

app.NoRoute(func(context *gin.Context) {
indexBytes, err := env.EmbedStaticAssets.ReadFile("dist/index.html")
if err != nil {
logrus.Fatal(err)
}
context.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
context.String(http.StatusOK, string(indexBytes))
})
}

api := app.Group("/api")
app.Use(middleware.Language)
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Expand Up @@ -10,7 +10,7 @@ let currentMode = modeProduction;
const frontendFolder = path.join(__dirname, "gofi-frontend");
const backendFolder = path.join(__dirname, "gofi-backend");
const frontendDistFolder = path.join(frontendFolder, "dist");
const backendDistFolder = path.join(backendFolder, "dist");
const backendDistFolder = path.join(backendFolder, "env", "dist");
const backendOutputFolder = path.join(backendFolder, "output");
const outputFolder = path.join(__dirname, "output");
const goPath = shell.exec("go env GOPATH", { silent: true }).stdout.trim();
Expand Down

0 comments on commit 16c28d4

Please sign in to comment.