You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oa/builtin/init.go

42 lines
979 B
Go

//
// init.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-18 17:07
// Distributed under terms of the GPL license.
//
package builtin
import (
"net/http"
"net/http/httputil"
"net/url"
"oa/builtin/fs"
"oa/cfg"
"oa/libs"
"github.com/veypi/OneBD/rest"
"github.com/veypi/utils/logv"
)
func Enable(app *rest.Application) {
if cfg.Config.FsPath != "" {
r := app.Router().SubRouter("fs")
r.Set("/*", "OPTIONS", libs.CorsAllowAny)
r.Use(libs.CorsAllowAny)
r.Any("/a/:aid/*p", fs.NewAppFs("/fs/a"))
r.Any("/u/:uid/*p", fs.NewUserFs("/fs/u"))
}
tsPorxy := httputil.NewSingleHostReverseProxy(logv.AssertFuncErr(url.Parse("http://v.v:8428")))
fsProxy := fs.NewFs("/home/v/cache/", "")
app.SetMux(func(w http.ResponseWriter, r *http.Request) func(http.ResponseWriter, *http.Request) {
if r.Host == "ts.oa.v" || r.Header.Get("mux") == "ts" {
return tsPorxy.ServeHTTP
} else if r.Host == "fs.oa.v" {
return fsProxy.ServeHTTP
}
return nil
})
}