🌱🏠 a cloud service to enable your own server (owned by you and running on your computer) to be accessible on the internet in seconds, no credit card required 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.

93 lines
2.8 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "log"
  6. "net/http"
  7. "os"
  8. "strconv"
  9. )
  10. func registerHowtoRoutes(app *FrontendApp) {
  11. app.handleWithSessionNotRequired(
  12. "/using-your-own-domain-name-with-greenhouse",
  13. func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
  14. templateData := struct {
  15. Subdomain string
  16. SubdomainDomain string
  17. }{
  18. SubdomainDomain: freeSubdomainDomain,
  19. }
  20. if session.TenantId != 0 {
  21. tenant, err := app.Model.GetTenant(session.TenantId)
  22. if err != nil {
  23. app.unhandledError(responseWriter, request, err)
  24. return
  25. }
  26. templateData.Subdomain = tenant.Subdomain
  27. }
  28. app.buildPageFromTemplate(responseWriter, request, session, "about-dns.html", templateData)
  29. },
  30. )
  31. app.handleWithSessionNotRequired(
  32. "/install-greenhouse-self-hosting-software-linux",
  33. func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
  34. app.buildPageFromTemplate(responseWriter, request, session, "install-linux.html", struct{}{})
  35. },
  36. )
  37. app.handleWithSessionNotRequired(
  38. "/install-greenhouse-self-hosting-software-mac",
  39. func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
  40. app.buildPageFromTemplate(responseWriter, request, session, "install-mac.html", struct{}{})
  41. },
  42. )
  43. app.handleWithSessionNotRequired(
  44. "/install-greenhouse-self-hosting-software-windows",
  45. func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
  46. app.buildPageFromTemplate(responseWriter, request, session, "install-windows.html", struct{}{})
  47. },
  48. )
  49. serveScripts := []string{
  50. "install.sh",
  51. "uninstall.sh",
  52. }
  53. for _, scriptFileName := range serveScripts {
  54. // this is how you do closures over the VALUE of a variable (not the variable itself) in golang
  55. // https://stackoverflow.com/questions/26692844/captured-closure-for-loop-variable-in-go
  56. scriptFileName := scriptFileName
  57. app.handleWithSessionNotRequired(
  58. fmt.Sprintf("/%s", scriptFileName),
  59. func(responseWriter http.ResponseWriter, request *http.Request, session Session) {
  60. file, err := os.OpenFile(fmt.Sprintf("frontend/static/%s", scriptFileName), os.O_RDONLY, 0755)
  61. if err != nil {
  62. log.Printf("/%s 404 not found: %+v", scriptFileName, err)
  63. http.Error(responseWriter, "404 not found", http.StatusNotFound)
  64. return
  65. }
  66. stat, err := file.Stat()
  67. if err != nil {
  68. log.Printf("/%s 500 internal server error: %+v", scriptFileName, err)
  69. http.Error(responseWriter, "500 internal server error", http.StatusInternalServerError)
  70. return
  71. }
  72. go postTelemetryFromRequest("release-download", request, app, scriptFileName)
  73. responseWriter.Header().Add("Content-Type", "application/x-sh")
  74. responseWriter.Header().Add("Content-Length", strconv.Itoa(int(stat.Size())))
  75. io.Copy(responseWriter, file)
  76. },
  77. )
  78. }
  79. }