split up in separate pages.
This commit is contained in:
parent
80a536c70e
commit
e0771c095b
@ -1,59 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"converge/pkg/templates"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FileHandlerFilter struct {
|
|
||||||
dir string
|
|
||||||
fileHandler http.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFileHandler(dir string) *FileHandlerFilter {
|
|
||||||
handler := FileHandlerFilter{
|
|
||||||
dir: dir,
|
|
||||||
fileHandler: http.FileServer(http.Dir(dir)),
|
|
||||||
}
|
|
||||||
return &handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (handler FileHandlerFilter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
contextPath := r.URL.Path
|
|
||||||
path := filepath.Join(handler.dir, contextPath)
|
|
||||||
fileInfo, err := os.Stat(path)
|
|
||||||
if err == nil && fileInfo.IsDir() {
|
|
||||||
contextPath = filepath.Join(contextPath, "index.html")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasSuffix(contextPath, ".html") {
|
|
||||||
handler.fileHandler.ServeHTTP(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
||||||
w.Header().Set("Pragma", "no-cache")
|
|
||||||
w.Header().Set("Expires", "0")
|
|
||||||
|
|
||||||
secure := ""
|
|
||||||
if r.TLS == nil {
|
|
||||||
secure = ""
|
|
||||||
} else {
|
|
||||||
secure = "s"
|
|
||||||
}
|
|
||||||
for _, header := range []string{"X-Forwarded-Proto", "X-Scheme", "X-Forwarded-Scheme"} {
|
|
||||||
values := r.Header.Values(header)
|
|
||||||
for _, value := range values {
|
|
||||||
if strings.ToLower(value) == "https" {
|
|
||||||
secure = "s"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
username, _ := os.LookupEnv("CONVERGE_USERNAME")
|
|
||||||
|
|
||||||
templates.Index(secure, r.Host, username).Render(
|
|
||||||
r.Context(), w)
|
|
||||||
}
|
|
@ -29,8 +29,12 @@ func pageHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
fallthrough
|
fallthrough
|
||||||
case "/":
|
case "/":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "/index.html":
|
case "index.html":
|
||||||
templates.Index(secure, r.Host, username).Render(r.Context(), w)
|
templates.AboutTab().Render(r.Context(), w)
|
||||||
|
case "usage.html":
|
||||||
|
templates.UsageTab(secure, r.URL.Host, username).Render(r.Context(), w)
|
||||||
|
case "downloads.html":
|
||||||
|
templates.DownloadsTab().Render(r.Context(), w)
|
||||||
default:
|
default:
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,9 @@ templ About() {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
templ AboutTab() {
|
||||||
|
@BasePage() {
|
||||||
|
@About()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,4 +36,11 @@ templ Downloads() {
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
templ DownloadsTab() {
|
||||||
|
@BasePage() {
|
||||||
|
@Downloads()
|
||||||
|
}
|
||||||
}
|
}
|
@ -120,3 +120,10 @@ templ Usage(secure string, host string, username string) {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
templ UsageTab(secure string, host string, username string) {
|
||||||
|
@BasePage() {
|
||||||
|
@Usage(secure, host, username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user