Files

52 lines
1.7 KiB
Go
Raw Permalink Normal View History

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2021-06-09 07:33:54 +08:00
package install
import (
"fmt"
"html"
"net/http"
2021-01-26 23:36:53 +08:00
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
2021-01-26 23:36:53 +08:00
"code.gitea.io/gitea/modules/web"
2021-06-09 07:33:54 +08:00
"code.gitea.io/gitea/routers/common"
2022-05-04 19:56:20 +08:00
"code.gitea.io/gitea/routers/web/healthcheck"
"code.gitea.io/gitea/routers/web/misc"
"code.gitea.io/gitea/services/forms"
)
2023-04-21 02:49:06 +08:00
// Routes registers the installation routes
2024-06-19 06:32:45 +08:00
func Routes() *web.Router {
base := web.NewRouter()
2026-03-08 17:59:46 +08:00
base.BeforeRouting(common.ProtocolMiddlewares()...)
base.Methods("GET, HEAD", "/assets/*", public.FileHandlerFunc())
2021-01-26 23:36:53 +08:00
2024-06-19 06:32:45 +08:00
r := web.NewRouter()
2026-03-08 17:59:46 +08:00
r.AfterRouting(common.MustInitSessioner(), installContexter())
2025-11-26 23:25:34 +08:00
r.Get("/", Install) // it must be on the root, because the "install.js" use the window.location to replace the "localhost" AppURL
2021-06-09 07:33:54 +08:00
r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall)
r.Get("/post-install", InstallDone)
r.Get("/-/web-theme/list", misc.WebThemeList)
r.Post("/-/web-theme/apply", misc.WebThemeApply)
2022-05-04 19:56:20 +08:00
r.Get("/api/healthz", healthcheck.Check)
2023-04-21 02:49:06 +08:00
r.NotFound(installNotFound)
base.Mount("", r)
return base
2021-01-26 23:36:53 +08:00
}
2022-01-20 19:41:25 +08:00
func installNotFound(w http.ResponseWriter, req *http.Request) {
w.Header().Add("Content-Type", "text/html; charset=utf-8")
2025-04-01 12:14:01 +02:00
w.Header().Add("Refresh", "1; url="+setting.AppSubURL+"/")
// do not use 30x status, because the "post-install" page needs to use 404/200 to detect if Gitea has been installed.
// the fetch API could follow 30x requests to the page with 200 status.
w.WriteHeader(http.StatusNotFound)
_, _ = fmt.Fprintf(w, `Not Found. <a href="%s">Go to default page</a>.`, html.EscapeString(setting.AppSubURL+"/"))
2022-01-20 19:41:25 +08:00
}