diff --git a/server/src/app/app.go b/server/src/app/app.go index 1321b5a..dd53425 100644 --- a/server/src/app/app.go +++ b/server/src/app/app.go @@ -1,14 +1,12 @@ package app import ( - "sirlab.de/go/knyt/engine" "sirlab.de/go/knyt/handler" ) type App struct { Config AppConfig Mux *handler.AuthMux - Eng *engine.Engine } func NewApp(config AppConfig) *App { diff --git a/server/src/handler/authmux.go b/server/src/handler/authmux.go index 02a27e2..f20fd4e 100644 --- a/server/src/handler/authmux.go +++ b/server/src/handler/authmux.go @@ -7,13 +7,18 @@ import ( type HandlerFunc func(http.ResponseWriter, *http.Request) type AuthMux struct { - mux *http.ServeMux + mux *http.ServeMux + Port int } func NewAuthMux() *AuthMux { - return &(AuthMux{ - mux: http.NewServeMux(), - }) + mux := AuthMux{ + mux: http.NewServeMux(), + Port: 32039, + } + http.Handle("/", mux.mux) + + return &mux } func (authMux *AuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -27,3 +32,7 @@ func (authMux *AuthMux) PublicHandleFunc(pattern string, handlerFunc HandlerFunc func (authMux *AuthMux) PublicHandle(pattern string, handler http.Handler) { authMux.mux.Handle(pattern, handler) } + +func (authMux *AuthMux) ListenAndServe() { + http.ListenAndServe(":32039", nil) +} diff --git a/server/src/knyt.go b/server/src/knyt.go index db86d24..bcac18c 100644 --- a/server/src/knyt.go +++ b/server/src/knyt.go @@ -4,35 +4,21 @@ import ( "fmt" "net/http" "sirlab.de/go/knyt/app" - "sirlab.de/go/knyt/engine" "sirlab.de/go/knyt/handler" - "sirlab.de/go/knyt/user" - "sirlab.de/go/knyt/users" ) func main() { appConfig := app.NewAppConfig() App := app.NewApp(appConfig) App.Mux = handler.NewAuthMux() - App.Eng = engine.NewEngine() - http.Handle("/", App.Mux) - - usrs := users.NewUsers() - u1 := user.NewUser("123", "Volkmar", user.ROLE_PLAYER) - u2 := user.NewUser("123", "Annabell", user.ROLE_GAMEMASTER) - usrs.AddUser(u1) - usrs.AddUser(u2) App.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit) // default handler - fsHandler := http.FileServer(http.Dir("../client/dist/")) + fsHandler := http.FileServer(http.Dir("../../client/dist/")) App.Mux.PublicHandle("/", fsHandler) - App.Mux.PublicHandleFunc("/api/sync", App.Eng.GetHttpHandler()) - go App.Eng.Run() - // start listening - fmt.Println("http://localhost:32039") - http.ListenAndServe(":32039", nil) + fmt.Printf("http://localhost:%d/\n", App.Mux.Port) + App.Mux.ListenAndServe() }