Browse Source

TODO for 404 page, front-end, back-end funcs

Vova Tkach 6 years ago
parent
commit
2808b34d3f
2 changed files with 20 additions and 5 deletions
  1. 7 4
      engine/wrapper/static.go
  2. 13 1
      main.go

+ 7 - 4
engine/wrapper/static.go

@@ -73,8 +73,6 @@ func (e *Wrapper) staticFile() bool {
 }
 
 func (e *Wrapper) printPageDefault() {
-	(*e.W).Header().Set("Content-Type", "text/html")
-
 	// Custom page
 	f, err := os.Open(e.DirVhostHome + "/htdocs" + "/index.html")
 	if err == nil {
@@ -84,21 +82,26 @@ func (e *Wrapper) printPageDefault() {
 	}
 
 	// Default page
+	(*e.W).Header().Set("Content-Type", "text/html")
 	(*e.W).Write(Templates.PageDefault)
 }
 
 func (e *Wrapper) printPage404() {
-	(*e.W).WriteHeader(http.StatusNotFound)
-	(*e.W).Header().Set("Content-Type", "text/html")
+	// TODO: Fix this
+	// http: multiple response.WriteHeader calls
+	// (*e.W).WriteHeader(http.StatusNotFound)
 
 	// Custom 404 error page
 	f, err := os.Open(e.DirVhostHome + "/htdocs" + "/404.html")
 	if err == nil {
 		defer f.Close()
+		// TODO: set status code 404 here
 		http.ServeFile(*e.W, e.R, e.DirVhostHome+"/htdocs"+"/404.html")
 		return
 	}
 
 	// Default error page
+	(*e.W).WriteHeader(http.StatusNotFound)
+	(*e.W).Header().Set("Content-Type", "text/html")
 	(*e.W).Write(Templates.PageError404)
 }

+ 13 - 1
main.go

@@ -117,6 +117,18 @@ func handler(w http.ResponseWriter, r *http.Request) {
 	// Create and start engine
 	wrapper.New(&w, r, host, port, FParamWwwDir, FVhostHomeDir, C_Debug).
 		Run(func(e *wrapper.Wrapper) bool {
-			return false
+			if e.R.URL.Path == "/cp" || strings.HasPrefix(e.R.URL.Path, "/cp/") {
+				return handleBackEnd(e)
+			} else {
+				return handleFrontEnd(e)
+			}
 		})
 }
+
+func handleFrontEnd(e *wrapper.Wrapper) bool {
+	return false
+}
+
+func handleBackEnd(e *wrapper.Wrapper) bool {
+	return false
+}