3
0

upd(system): additional route middleware, route context

This commit is contained in:
Tit Petric
2019-01-16 12:28:50 +01:00
parent 3dcf10e398
commit 6cafce4d03
3 changed files with 8 additions and 6 deletions
-3
View File
@@ -38,9 +38,6 @@ func (c *appFlags) Validate() error {
if err := c.oidc.Validate(); err != nil {
return err
}
//if err := c.jwt.Validate(); err != nil {
// return err
//}
return nil
}
+4 -1
View File
@@ -1,6 +1,7 @@
package service
import (
"context"
"fmt"
"reflect"
"runtime"
@@ -18,9 +19,11 @@ import (
"github.com/crusttech/crust/system/rest"
)
func Routes() *chi.Mux {
func Routes(ctx context.Context) *chi.Mux {
r := chi.NewRouter()
r.Use(handleCORS)
r.Use(middleware.RealIP)
r.Use(middleware.RequestID)
// Only protect application routes with JWT
r.Group(func(r chi.Router) {
+4 -2
View File
@@ -5,7 +5,9 @@ import (
"log"
"net"
"net/http"
"os"
"github.com/SentimensRG/ctx"
"github.com/SentimensRG/ctx/sigctx"
"github.com/pkg/errors"
"github.com/titpetric/factory"
@@ -74,7 +76,7 @@ func Init() error {
}
func Start() error {
log.Printf("Starting auth, version: %v, built on: %v", version.Version, version.BuildTime)
log.Printf("Starting "+os.Args[0]+", version: %v, built on: %v", version.Version, version.BuildTime)
log.Println("Starting http server on address " + flags.http.Addr)
listener, err := net.Listen("tcp", flags.http.Addr)
if err != nil {
@@ -84,9 +86,9 @@ func Start() error {
if flags.monitor.Interval > 0 {
go metrics.NewMonitor(flags.monitor.Interval)
}
go http.Serve(listener, Routes())
var deadline = sigctx.New()
go http.Serve(listener, Routes(ctx.AsContext(deadline)))
<-deadline.Done()
return nil