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.

routes.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package install
  4. import (
  5. "fmt"
  6. "html"
  7. "net/http"
  8. "code.gitea.io/gitea/modules/public"
  9. "code.gitea.io/gitea/modules/setting"
  10. "code.gitea.io/gitea/modules/web"
  11. "code.gitea.io/gitea/routers/common"
  12. "code.gitea.io/gitea/routers/web/healthcheck"
  13. "code.gitea.io/gitea/services/forms"
  14. )
  15. // Routes registers the installation routes
  16. func Routes() *web.Route {
  17. base := web.NewRoute()
  18. base.Use(common.ProtocolMiddlewares()...)
  19. base.Methods("GET, HEAD", "/assets/*", public.FileHandlerFunc())
  20. r := web.NewRoute()
  21. r.Use(common.Sessioner(), Contexter())
  22. r.Get("/", Install) // it must be on the root, because the "install.js" use the window.location to replace the "localhost" AppURL
  23. r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall)
  24. r.Get("/post-install", InstallDone)
  25. r.Get("/api/healthz", healthcheck.Check)
  26. r.NotFound(installNotFound)
  27. base.Mount("", r)
  28. return base
  29. }
  30. func installNotFound(w http.ResponseWriter, req *http.Request) {
  31. w.Header().Add("Content-Type", "text/html; charset=utf-8")
  32. w.Header().Add("Refresh", fmt.Sprintf("1; url=%s", setting.AppSubURL+"/"))
  33. // do not use 30x status, because the "post-install" page needs to use 404/200 to detect if Gitea has been installed.
  34. // the fetch API could follow 30x requests to the page with 200 status.
  35. w.WriteHeader(http.StatusNotFound)
  36. _, _ = fmt.Fprintf(w, `Not Found. <a href="%s">Go to default page</a>.`, html.EscapeString(setting.AppSubURL+"/"))
  37. }