Browse Source

Custom error page 404

Vova Tkach 6 years ago
parent
commit
669678ba20
3 changed files with 49 additions and 0 deletions
  1. 10 0
      engine/wrapper/static.go
  2. 24 0
      hosts/localhost/htdocs/404.html
  3. 15 0
      hosts/localhost/template/index.html

+ 10 - 0
engine/wrapper/static.go

@@ -94,5 +94,15 @@ func (e *Wrapper) printPageDefault() {
 func (e *Wrapper) printPage404() {
 	(*e.W).WriteHeader(http.StatusNotFound)
 	(*e.W).Header().Set("Content-Type", "text/html")
+
+	// Custom 404 error page
+	f, err := os.Open(e.DirVhostHome + "/htdocs" + "/404.html")
+	if err == nil {
+		defer f.Close()
+		http.ServeFile(*e.W, e.R, e.DirVhostHome+"/htdocs"+"/404.html")
+		return
+	}
+
+	// Default error page
 	(*e.W).Write(Templates.PageError404)
 }

+ 24 - 0
hosts/localhost/htdocs/404.html

@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<meta name="theme-color" content="#205081" />
+		<title>Error 404</title>
+		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+		<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8" />
+		<link rel="shortcut icon" href="/assets/sys/fave.ico" type="image/x-icon" />
+		<link rel="stylesheet" type="text/css" media="all" href="/assets/sys/styles.css" />
+		<style type="text/css">a { color: #fff; }</style>
+	</head>
+	<body>
+		<div class="wrapper">
+			<div class="logo">
+				<div class="svg">
+					<img src="/assets/sys/logo.svg" width="150" height="150" />
+				</div>
+			</div>
+			<h1>Error 404</h1>
+			<h2><a href="/">First Page</a></h2>
+		</div>
+	</body>
+</html>

+ 15 - 0
hosts/localhost/template/index.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<meta name="theme-color" content="#205081" />
+		<title>Index template</title>
+		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+		<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8" />
+		<link rel="shortcut icon" href="/assets/sys/fave.ico" type="image/x-icon" />
+		<link rel="stylesheet" type="text/css" media="all" href="/assets/sys/styles.css" />
+	</head>
+	<body>
+		Index template
+	</body>
+</html>