🌱🏠 instant least-authority port-forwarding (with automatic HTTPS) for anyone, anywhere! We **really** don't want your TLS private keys, you can keep them 😃 https://greenhouse.server.garden/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8 KiB

package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
)
func registerHowtoRoutes(app *FrontendApp) {
app.handleWithSessionNotRequired(
"/using-your-own-domain-name-with-greenhouse",
func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
templateData := struct {
Subdomain string
SubdomainDomain string
}{
SubdomainDomain: freeSubdomainDomain,
}
if session.TenantId != 0 {
tenant, err := app.Model.GetTenant(session.TenantId)
if err != nil {
app.unhandledError(responseWriter, request, err)
return
}
templateData.Subdomain = tenant.Subdomain
}
app.buildPageFromTemplate(responseWriter, request, session, "about-dns.html", templateData)
},
)
app.handleWithSessionNotRequired(
"/install-greenhouse-self-hosting-software-linux",
func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
app.buildPageFromTemplate(responseWriter, request, session, "install-linux.html", struct{}{})
},
)
app.handleWithSessionNotRequired(
"/install-greenhouse-self-hosting-software-mac",
func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
app.buildPageFromTemplate(responseWriter, request, session, "install-mac.html", struct{}{})
},
)
app.handleWithSessionNotRequired(
"/install-greenhouse-self-hosting-software-windows",
func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
app.buildPageFromTemplate(responseWriter, request, session, "install-windows.html", struct{}{})
},
)
serveScripts := []string{
"install.sh",
"uninstall.sh",
}
for _, scriptFileName := range serveScripts {
// this is how you do closures over the VALUE of a variable (not the variable itself) in golang
// https://stackoverflow.com/questions/26692844/captured-closure-for-loop-variable-in-go
scriptFileName := scriptFileName
app.handleWithSessionNotRequired(
fmt.Sprintf("/%s", scriptFileName),
func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
file, err := os.OpenFile(fmt.Sprintf("frontend/static/%s", scriptFileName), os.O_RDONLY, 0755)
if err != nil {
log.Printf("/%s 404 not found: %+v", scriptFileName, err)
http.Error(responseWriter, "404 not found", http.StatusNotFound)
return
}
stat, err := file.Stat()
if err != nil {
log.Printf("/%s 500 internal server error: %+v", scriptFileName, err)
http.Error(responseWriter, "500 internal server error", http.StatusInternalServerError)
return
}
go postTelemetryFromRequest("release-download", request, app, scriptFileName)
responseWriter.Header().Add("Content-Type", "application/x-sh")
responseWriter.Header().Add("Content-Length", strconv.Itoa(int(stat.Size())))
io.Copy(responseWriter, file)
},
)
}
}