Skip to content

Commit

Permalink
Use 404 page for not found subtopic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Raggaer committed Dec 22, 2018
1 parent b32eb5e commit 980badb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/controllers/lua.go
Expand Up @@ -146,10 +146,14 @@ func LuaPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
lua.SetI18nUserData(s, language)

// Retrieve compiled proto
proto, err := lua.CompiledPageList.Get(filepath.Join("pages", pageName, r.Method+".lua"))
protoPath := filepath.Join("pages", pageName, r.Method+".lua")
if !lua.CompiledPageList.Exists(protoPath) {
protoPath = filepath.Join("pages", "404", r.Method+".lua")
}
proto, err := lua.CompiledPageList.Get(protoPath)
if err != nil {
w.WriteHeader(404)
util.Logger.Logger.Errorf("Cannot find lua proto, subtopic source: %v", pageName, err)
util.Logger.Logger.Errorf("Cannot find lua proto, subtopic source (%s) %v", pageName, err)
return
}

Expand All @@ -159,7 +163,7 @@ func LuaPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
proto,
); err != nil {
w.WriteHeader(404)
util.Logger.Logger.Errorf("Cannot get %v subtopic source: %v", pageName, err)
util.Logger.Logger.Errorf("Cannot get %v subtopic source (%s) %v", pageName, err)
return
}

Expand Down
11 changes: 11 additions & 0 deletions app/lua/state.go
Expand Up @@ -45,6 +45,17 @@ type stateList struct {
Type string
}

// Exists checks if a proto path exists
func (s *compiledStateList) Exists(path string) bool {
path = strings.ToLower(path)
for p, _ := range s.List {
if strings.ToLower(p) == path {
return true
}
}
return false
}

// CompileFiles compiles all lua files into function protos
func (s *compiledStateList) CompileFiles(dir string) error {
s.rw.Lock()
Expand Down

1 comment on commit 980badb

@joseluis2g
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🥇

Please sign in to comment.