How to run angular build under golang revel framework

312 views Asked by At

I have one angular build files in public folder in revel appplication. I want to run those html and js files under revel application.

GET     /   Static.Serve("public")

I gave the above code in routes file. When I try in browser, it's showing "Forbidden Directory listing not allowed"

2

There are 2 answers

0
Saiju On BEST ANSWER

add these two line in routes file. Here all GET request will move to app controller Index function.

GET     /                                       App.Index
GET     /*                                      App.Index

add below code in app controller file.

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")
    }
}
2
J-Jacques M On

Not big deal, you were close

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

Then your angulars should do his works.