如何在golang revel框架下运行angular搭建

How to run angular build under golang revel framework

我在 Revel 应用程序的 public 文件夹中有一个 angular 构建文件。 我想 运行 那些 html 和 revel 应用程序下的 js 文件。

GET     /   Static.Serve("public")

我在路由文件中给出了上面的代码。当我在浏览器中尝试时,它显示“禁止访问 目录列表不允许

没什么大不了的,你很接近

GET         /                       Static.Serve("public/index.html")

那么你的角应该做他的工作。

在路由文件中添加这两行。这里所有的 GET 请求都会移动到 app controller Index 函数。

GET     /                                       App.Index
GET     /*                                      App.Index

在应用程序控制器文件中添加以下代码。

func (c App) Index() revel.Result {
    dir, doc := path.Split(c.Request.URL.Path)
    ext := filepath.Ext(doc)
    if doc == "" || ext == "" {
        return c.RenderFileName("./public/index.html", "inline")
    } else {
        if _, err := os.Stat("./public/" + path.Join(dir, doc)); err != nil {
            return c.RenderFileName("./public/index.html", "inline")
        }
        return c.RenderFileName("./public/" + path.Join(dir, doc), "inline")
    }
}