Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Nov 13, 2023
1 parent 1c11167 commit 760d531
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base href="{{.BaseURL}}">
<link rel="preload" href="carimbo.wasm" as="fetch" type="application/wasm" crossorigin />
<link rel="preload" href="bundle.zip" as="fetch" type="application/zip" crossorigin />
<title>Carimbo</title>
Expand Down
30 changes: 28 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"log"
"net/http"
"os"
"path"
"regexp"
"strings"
"sync"
"text/template"
)

//go:embed index.html
Expand Down Expand Up @@ -207,6 +209,7 @@ func bundleHandler(w http.ResponseWriter, r *http.Request) {
_, org, repo, release := getOrgRepoReleaseFromURL(r.URL.Path)
bundle, err := fetchBundle(org, repo, release)
if err != nil {
log.Printf("[fetchBundle]: error %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -221,8 +224,31 @@ func favIconHandler(w http.ResponseWriter, r *http.Request) {
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.Write(html)
tmpl, err := template.New("index").Parse(string(html))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

var protocol string
if r.TLS == nil {
protocol = "http"
} else {
protocol = "https"
}

baseURL := fmt.Sprintf("%s://%s%s/", protocol, r.Host, strings.TrimRight(path.Clean(r.URL.Path), "/"))

data := struct {
BaseURL string
}{
BaseURL: baseURL,
}

if err := tmpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func main() {
Expand Down

0 comments on commit 760d531

Please sign in to comment.