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