-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_with_ui.go
35 lines (28 loc) · 901 Bytes
/
router_with_ui.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
// +build ui
package main
import (
"net/http"
"github.com/alxarno/swap/settings"
"github.com/alxarno/swap/src/api"
engine "github.com/alxarno/swap/src/messages"
"github.com/gobuffalo/packr"
"github.com/gorilla/mux"
"golang.org/x/net/websocket"
)
func newRouter() *mux.Router {
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/info", info)
myRouter.HandleFunc("/getFile/{link}/{name}", downloadFile)
myRouter.Handle("/ws", websocket.Handler(engine.ConnectionHandler))
api.RegisterEndpoints(newSubRoute(myRouter)("/api"))
box := packr.NewBox("./ui")
myRouter.Handle("/", http.FileServer(box))
myRouter.Handle("/{key1}", http.FileServer(box))
myRouter.Handle("/{key1}/{key2}", http.FileServer(box))
myRouter.Use(logginMiddleware)
if settings.ServiceSettings.Service.CORS {
myRouter.Use(_CORSMiddleware)
}
myRouter.Use(AdditionalHeaders)
return myRouter
}