mirror of
https://gitea.com/gitea/gitea-mirror.git
synced 2026-03-20 03:40:27 +00:00
Principles: let the caller decide what it needs, but not let the framework (middleware) guess what it should do. Then a lot of hacky code can be removed. And some FIXMEs can be fixed. This PR introduces a new kind of middleware: "PreMiddleware", it will be executed before all other middlewares on the same routing level, then a route can declare its options for other middlewares. By the way, allow the workflow badge to be accessed by Basic or OAuth2 auth. Fixes: https://github.com/go-gitea/gitea/pull/36830 Fixes: https://github.com/go-gitea/gitea/issues/36859
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package install
|
|
|
|
import (
|
|
"fmt"
|
|
"html"
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/modules/public"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/web"
|
|
"code.gitea.io/gitea/routers/common"
|
|
"code.gitea.io/gitea/routers/web/healthcheck"
|
|
"code.gitea.io/gitea/routers/web/misc"
|
|
"code.gitea.io/gitea/services/forms"
|
|
)
|
|
|
|
// Routes registers the installation routes
|
|
func Routes() *web.Router {
|
|
base := web.NewRouter()
|
|
base.BeforeRouting(common.ProtocolMiddlewares()...)
|
|
|
|
base.Methods("GET, HEAD", "/assets/*", public.FileHandlerFunc())
|
|
|
|
r := web.NewRouter()
|
|
r.AfterRouting(common.MustInitSessioner(), installContexter())
|
|
|
|
r.Get("/", Install) // it must be on the root, because the "install.js" use the window.location to replace the "localhost" AppURL
|
|
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)
|
|
r.Get("/api/healthz", healthcheck.Check)
|
|
|
|
r.NotFound(installNotFound)
|
|
|
|
base.Mount("", r)
|
|
return base
|
|
}
|
|
|
|
func installNotFound(w http.ResponseWriter, req *http.Request) {
|
|
w.Header().Add("Content-Type", "text/html; charset=utf-8")
|
|
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+"/"))
|
|
}
|