mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-07 07:42:45 +01:00
@@ -3,18 +3,16 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst"
|
||||
"github.com/SecurityBrewery/catalyst/cmd"
|
||||
"github.com/SecurityBrewery/catalyst/database/busdb"
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
"github.com/SecurityBrewery/catalyst/hooks"
|
||||
"github.com/SecurityBrewery/catalyst/role"
|
||||
"github.com/SecurityBrewery/catalyst/test"
|
||||
@@ -36,30 +34,25 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
demoUser := &models.UserResponse{ID: "demo", Roles: []string{role.Admin}}
|
||||
demoUser := &model.UserResponse{ID: "demo", Roles: []string{role.Admin}}
|
||||
ctx := busdb.UserContext(context.Background(), demoUser)
|
||||
if err := test.SetupTestData(ctx, theCatalyst.DB); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// proxy static requests
|
||||
theCatalyst.Server.NoRoute(
|
||||
sessions.Sessions(catalyst.SessionName, cookie.NewStore(config.Secret)),
|
||||
catalyst.Authenticate(theCatalyst.DB, config.Auth),
|
||||
catalyst.AuthorizeBlockedUser,
|
||||
proxy,
|
||||
)
|
||||
theCatalyst.Server.With(catalyst.Authenticate(theCatalyst.DB, config.Auth), catalyst.AuthorizeBlockedUser()).NotFound(proxy)
|
||||
|
||||
if err = theCatalyst.Server.RunWithSigHandler(); err != nil {
|
||||
if err := http.ListenAndServe(":8000", theCatalyst.Server); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func proxy(ctx *gin.Context) {
|
||||
func proxy(w http.ResponseWriter, r *http.Request) {
|
||||
u, _ := url.Parse("http://localhost:8080")
|
||||
proxy := httputil.NewSingleHostReverseProxy(u)
|
||||
|
||||
ctx.Request.Host = ctx.Request.URL.Host
|
||||
r.Host = r.URL.Host
|
||||
|
||||
proxy.ServeHTTP(ctx.Writer, ctx.Request)
|
||||
proxy.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user