mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-18 10:29:43 +00:00
Fix error page not rendering & make it more beautiful
This commit is contained in:
parent
241f7a57ec
commit
cdd6727049
3 changed files with 25 additions and 14 deletions
22
404.html
22
404.html
|
@ -3,16 +3,16 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<title>Not found</title>
|
<title>%status</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://design.codeberg.org/design-kit/codeberg.css" />
|
<link rel="stylesheet" href="https://design.codeberg-test.org/design-kit/codeberg.css" />
|
||||||
<link href="https://fonts.codeberg.org/dist/inter/Inter%20Web/inter.css" rel="stylesheet" />
|
<link href="https://fonts.codeberg.org/dist/inter/Inter%20Web/inter.css" rel="stylesheet" />
|
||||||
<link href="https://fonts.codeberg.org/dist/fontawesome5/css/all.min.css" rel="stylesheet" />
|
<link href="https://fonts.codeberg.org/dist/fontawesome5/css/all.min.css" rel="stylesheet" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
margin: 0; padding: 1rem; box-sizing: border-box;
|
margin: 0; padding: 1rem; box-sizing: border-box;
|
||||||
width: 100%; min-height: 100vw;
|
width: 100%; min-height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -21,12 +21,16 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<i class="fa fa-bug" style="font-size: 96px"></i>
|
<i class="fa fa-bug text-primary" style="font-size: 96px;"></i>
|
||||||
<h1>You found a bug!</h1>
|
<h1 class="mb-0 text-primary">
|
||||||
<h3>Sorry, this page doesn't exist or is otherwise inaccessible (code %status)</h3>
|
You found a bug!
|
||||||
<small>
|
</h1>
|
||||||
<img src="https://design.codeberg.org/logo-kit/icon.svg">
|
<h5 class="text-center" style="max-width: 25em;">
|
||||||
Website powered by <a href="https://codeberg.page">Codeberg Pages</a>
|
Sorry, this page doesn't exist or is inaccessible for other reasons (%status)
|
||||||
|
</h5>
|
||||||
|
<small class="text-muted">
|
||||||
|
<img src="https://design.codeberg-test.org/logo-kit/icon.svg" class="align-top">
|
||||||
|
Static pages made easy - <a href="https://codeberg.page">Codeberg Pages</a>
|
||||||
</small>
|
</small>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -14,3 +14,5 @@ var tlsConfig = &tls.Config{
|
||||||
PreferServerCipherSuites: true,
|
PreferServerCipherSuites: true,
|
||||||
// TODO: optimize cipher suites, minimum TLS version, etc.
|
// TODO: optimize cipher suites, minimum TLS version, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: HSTS header with includeSubdomains & preload for MainDomainSuffix and RawDomain
|
||||||
|
|
13
handler.go
13
handler.go
|
@ -148,7 +148,8 @@ func handler(ctx *fasthttp.RequestCtx) {
|
||||||
// with the provided status code.
|
// with the provided status code.
|
||||||
func returnErrorPage(ctx *fasthttp.RequestCtx, code int) {
|
func returnErrorPage(ctx *fasthttp.RequestCtx, code int) {
|
||||||
ctx.Response.SetStatusCode(code)
|
ctx.Response.SetStatusCode(code)
|
||||||
ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte(strconv.Itoa(code))))
|
ctx.Response.Header.SetContentType("text/html; charset=utf-8")
|
||||||
|
ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte(strconv.Itoa(code) + " " + fasthttp.StatusMessage(code))))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch
|
// getBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch
|
||||||
|
@ -186,10 +187,14 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t
|
||||||
// Check if the branch exists and when it was modified
|
// Check if the branch exists and when it was modified
|
||||||
if options.BranchTimestamp == (time.Time{}) {
|
if options.BranchTimestamp == (time.Time{}) {
|
||||||
targetBranch, options.BranchTimestamp = getBranchTimestamp(targetOwner, targetRepo, targetBranch)
|
targetBranch, options.BranchTimestamp = getBranchTimestamp(targetOwner, targetRepo, targetBranch)
|
||||||
if options.BranchTimestamp == (time.Time{}) {
|
|
||||||
ctx.Response.SetStatusCode(fasthttp.StatusNotFound)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle repositories with no/broken pages setup
|
||||||
|
if options.BranchTimestamp == (time.Time{}) || targetBranch == "" {
|
||||||
|
ctx.Response.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
ctx.Response.Header.SetContentType("text/html; charset=utf-8")
|
||||||
|
ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte("pages not set up for this repo")))
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the browser has a cached version
|
// Check if the browser has a cached version
|
||||||
|
|
Loading…
Reference in a new issue