如何在Go中加载角度构建文件

我的Go项目中有一个dist文件夹。包含角度构建文件。

import (
    "github.com/gin-contrib/cors"
    "github.com/gin-gonic/contrib/static"
    "github.com/gin-gonic/gin"
)
func SetRoutes() *gin.Engine {
    router := gin.Default()
    router.Use(cors.Default())
    router.Use(static.Serve("/",static.LocalFile("./client/dist",true)))
    router.Run(":8080")
}

使用上面的代码,我可以提供dist文件夹文件。但是,如果刷新浏览器,它将无法获取这些文件。显示错误“找不到404页面”。

a258543020 回答:如何在Go中加载角度构建文件

router.Static("/","./client/dist")

尝试此代码。应该可以。

,

添加到@Dulquer答案中时,请确保“ dist”文件夹包含“ index.html”文件作为直接子文件,因为“ ng build”创建的文件夹的“ your-project-name”包含“ index.html”并放置在“ dist”文件夹。

本文链接:https://www.f2er.com/3103721.html

大家都在问