-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (43 loc) · 1.12 KB
/
main.go
File metadata and controls
55 lines (43 loc) · 1.12 KB
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
package main
import (
"github.com/blocktop/mp-common/server"
"github.com/blocktop/mp-common/server/middleware"
"github.com/blocktop/mp-web/config"
"github.com/go-chi/chi"
chim "github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
"io/ioutil"
"net/http"
"os"
"time"
)
func main() {
cfg := config.GetConfig()
r := chi.NewMux()
r.Use(middleware.HealthMiddleware)
r.Use(chim.Timeout(time.Duration(cfg.HTTPServerRequestTimeout) * time.Second))
cors := cors.New(cors.Options{
AllowedHeaders: []string{"*"},
})
r.Use(cors.Handler)
setRoutes(r)
server.RunHTTPServer(r)
os.Exit(0)
}
var stellarTOML string
func setRoutes(r *chi.Mux) {
r.Get("/health", middleware.HealthHandler)
r.Get("/.well-known/stellar.toml", handleGetStellarTOML)
r.Handle("/*", http.FileServer(Dir(false, "/assets")))
}
func handleGetStellarTOML(w http.ResponseWriter, r *http.Request) {
if len(stellarTOML) == 0 {
cfg := config.GetConfig()
toml, err := ioutil.ReadFile(cfg.StellarTOMLPath)
if err != nil {
server.ResponseError(w, http.StatusInternalServerError, server.NOFILE, err)
return
}
server.ResponseText(w, toml)
}
}