mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-27 11:35:04 +08:00
fix (plugin): order of plugin init
Before this we couldn't have a Endpoint plugin relying on values coming from the config as the config wasn't initialised yet. This fixes it
This commit is contained in:
13
cmd/main.go
13
cmd/main.go
@ -14,10 +14,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
start(Build(App{}))
|
var (
|
||||||
|
router *mux.Router = mux.NewRouter()
|
||||||
|
app = App{}
|
||||||
|
)
|
||||||
|
Build(router, app)
|
||||||
|
Run(router, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(routes *mux.Router) {
|
func Run(routes *mux.Router, app App) {
|
||||||
// Routes are served via plugins to avoid getting stuck with plain HTTP. The idea is to
|
// Routes are served via plugins to avoid getting stuck with plain HTTP. The idea is to
|
||||||
// support many more protocols in the future: HTTPS, HTTP2, TOR or whatever that sounds
|
// support many more protocols in the future: HTTPS, HTTP2, TOR or whatever that sounds
|
||||||
// fancy I don't know much when this got written: IPFS, solid, ...
|
// fancy I don't know much when this got written: IPFS, solid, ...
|
||||||
@ -30,9 +35,13 @@ func start(routes *mux.Router) {
|
|||||||
InitLogger()
|
InitLogger()
|
||||||
InitConfig()
|
InitConfig()
|
||||||
InitPluginList(embed.EmbedPluginList)
|
InitPluginList(embed.EmbedPluginList)
|
||||||
|
for _, obj := range Hooks.Get.HttpEndpoint() {
|
||||||
|
obj(routes, &app)
|
||||||
|
}
|
||||||
for _, fn := range Hooks.Get.Onload() {
|
for _, fn := range Hooks.Get.Onload() {
|
||||||
fn()
|
fn()
|
||||||
}
|
}
|
||||||
|
CatchAll(routes, app)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, obj := range Hooks.Get.Starter() {
|
for _, obj := range Hooks.Get.Starter() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|||||||
@ -16,11 +16,8 @@ import (
|
|||||||
. "github.com/mickael-kerjean/filestash/server/middleware"
|
. "github.com/mickael-kerjean/filestash/server/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Build(a App) *mux.Router {
|
func Build(r *mux.Router, a App) {
|
||||||
var (
|
var middlewares []Middleware
|
||||||
r *mux.Router = mux.NewRouter()
|
|
||||||
middlewares []Middleware
|
|
||||||
)
|
|
||||||
|
|
||||||
// API for Session
|
// API for Session
|
||||||
session := r.PathPrefix(WithBase("/api/session")).Subrouter()
|
session := r.PathPrefix(WithBase("/api/session")).Subrouter()
|
||||||
@ -121,8 +118,10 @@ func Build(a App) *mux.Router {
|
|||||||
initDebugRoutes(r)
|
initDebugRoutes(r)
|
||||||
}
|
}
|
||||||
initPluginsRoutes(r, &a)
|
initPluginsRoutes(r, &a)
|
||||||
|
}
|
||||||
|
|
||||||
middlewares = []Middleware{SecureHeaders, PluginInjector}
|
func CatchAll(r *mux.Router, a App) {
|
||||||
|
middlewares := []Middleware{SecureHeaders, PluginInjector}
|
||||||
r.PathPrefix(WithBase("/admin")).Handler(http.HandlerFunc(NewMiddlewareChain(ServeBackofficeHandler, middlewares, a))).Methods("GET")
|
r.PathPrefix(WithBase("/admin")).Handler(http.HandlerFunc(NewMiddlewareChain(ServeBackofficeHandler, middlewares, a))).Methods("GET")
|
||||||
middlewares = []Middleware{IndexHeaders, SecureHeaders, PluginInjector}
|
middlewares = []Middleware{IndexHeaders, SecureHeaders, PluginInjector}
|
||||||
if os.Getenv("LEGACY") == "true" { // TODO: remove once migration is done
|
if os.Getenv("LEGACY") == "true" { // TODO: remove once migration is done
|
||||||
@ -130,7 +129,6 @@ func Build(a App) *mux.Router {
|
|||||||
} else {
|
} else {
|
||||||
r.PathPrefix("/").Handler(http.HandlerFunc(NewMiddlewareChain(ServeFrontofficeHandler, middlewares, a))).Methods("GET", "POST")
|
r.PathPrefix("/").Handler(http.HandlerFunc(NewMiddlewareChain(ServeFrontofficeHandler, middlewares, a))).Methods("GET", "POST")
|
||||||
}
|
}
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDebugRoutes(r *mux.Router) {
|
func initDebugRoutes(r *mux.Router) {
|
||||||
@ -165,10 +163,6 @@ func initDebugRoutes(r *mux.Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initPluginsRoutes(r *mux.Router, a *App) {
|
func initPluginsRoutes(r *mux.Router, a *App) {
|
||||||
// Endpoints handle by plugins
|
|
||||||
for _, obj := range Hooks.Get.HttpEndpoint() {
|
|
||||||
obj(r, a)
|
|
||||||
}
|
|
||||||
// frontoffice overrides: it is the mean by which plugin can interact with the frontoffice
|
// frontoffice overrides: it is the mean by which plugin can interact with the frontoffice
|
||||||
for _, obj := range Hooks.Get.FrontendOverrides() {
|
for _, obj := range Hooks.Get.FrontendOverrides() {
|
||||||
r.HandleFunc(obj, func(res http.ResponseWriter, req *http.Request) {
|
r.HandleFunc(obj, func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user