This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (53 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/gostones/goboot/cf/redis"
"github.com/gostones/goboot/config"
"github.com/gostones/goboot/logging"
"github.com/gostones/goboot/web"
"github.com/gostones/goboot/web/gorilla"
"github.com/justinas/alice"
)
var settings = config.AppSettings()
var log = logging.Logger()
var redisClient = redis.NewRedisClient()
func authHandler(authKey string) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Debugf("internalAuthHandler begin: %v", r.URL)
key := r.URL.Query().Get("key")
if key == "" || key != authKey {
http.Error(w, "internalAuthHandler", http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
log.Debugf("internalAuthHandler end: %v", r.URL)
})
}
}
func main() {
startServer()
}
func startServer() {
var router = mux.NewRouter()
var gs = gorilla.NewGorillaServer(router)
//ping
router.HandleFunc("/ping", pingHandler)
//internal proxy access
authKey := internalAuthKey()
guard := alice.New(authHandler(authKey))
router.Handle("/internal/fs/ls", guard.ThenFunc(HandleFsLsInternal())).Methods("GET")
router.Handle("/internal/fs/content", guard.ThenFunc(HandleFsGetInternal()))
//proxy
appHome, err := createAppHome()
if err != nil {
panic(err)
}
appId := "dashboard"
accountId := "test"
shinyGuard := alice.New()
ps := NewProxyServer(gs.Port(), appHome, appId, accountId, authKey)
ps.Handle("/app/shiny", router, shinyGuard)
web.Run(gs)
}