web server now serves inlined resources as static assets

This commit is contained in:
Sven Vogel 2023-12-02 23:41:47 +01:00
parent 9733bd2f07
commit 8e12c4869b
9 changed files with 9 additions and 7 deletions

View File

@ -1,8 +1,8 @@
FROM golang:1.20-alpine
WORKDIR /usr/src/app
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod index-inlined-minified.html main.go ./
COPY go.mod index.html main.go ./
ADD assets ./assets/
RUN go mod download && go mod verify
RUN go build -v -o /usr/local/bin/app ./...

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

File diff suppressed because one or more lines are too long

View File

@ -7,14 +7,14 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="darkreader-lock"> <!-- Request dark reader to ignore this site. See: https://github.com/darkreader/darkreader/blob/main/CONTRIBUTING.md#disabling-dark-reader-on-your-site -->
<title>Montehaselino - Automatic Status Response</title>
<link href="master.css" rel="stylesheet"/>
<link href="assets/master.css" rel="stylesheet"/>
</head>
<body>
<div>
<div id="cloud1"></div>
<div id="cloud2"></div>
<div id="cloud3"></div>
<img id="mountain" src="res/svg/error-page-overlay.svg" alt="">
<img id="mountain" src="assets/res/svg/error-page-overlay.svg" alt="">
<div id="rocks"></div>
<h1>ERROR</h1>
<h2>{{.Code}}</h2>

View File

@ -52,7 +52,7 @@ func genStatus(request string) StatusData {
// create and init page status
var status StatusData
status.Code = "500"
status.Message = fmt.Sprintf("Invalid error response code recieved: %.5s[..]", request)
status.Message = fmt.Sprintf("Invalid error response code recieved: `%.5s`", request)
status.Response = 500
// check if we have a valid status code
@ -74,7 +74,7 @@ func genStatus(request string) StatusData {
func main() {
// load template
tmpl, err := template.ParseFiles("index-inlined-minified.html")
tmpl, err := template.ParseFiles("index.html")
if err != nil {
log.Fatal(err)
}
@ -86,6 +86,9 @@ func main() {
tmpl.Execute(w, status)
})
// serve static assets
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
var address = fmt.Sprintf("%s:%s", os.Getenv("BIND"), os.Getenv("PORT"))
log.Fatal(http.ListenAndServe(address, nil))