-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.go
More file actions
49 lines (39 loc) · 1.55 KB
/
routes.go
File metadata and controls
49 lines (39 loc) · 1.55 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
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
// CORS middleware
func enableCORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Allow all origins — for dev only, restrict in production!
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
// Handle preflight request
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}
func setupRoutes() *mux.Router {
router := mux.NewRouter()
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Server is up and running 🚀")
})
router.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "OK")
})
router.HandleFunc("/current-tokens", getCurrentTokens).Methods("GET")
// router.HandleFunc("/token-info", getTokenInfo).Methods("GET")
router.HandleFunc("/token-updates/{tokenID}", getTransactionsByTokenID).Methods("GET")
router.HandleFunc("/current-tokens/{peerID}", getCurrentTokensByPeerID).Methods("GET")
router.HandleFunc("/token-info/{tokenID}", getTokenInfoByTokenID).Methods("GET")
// router.HandleFunc("/transactions/upsert", upsertTransactionHandler).Methods("POST")
router.HandleFunc("/latesttoken", getLatestMintedToken).Methods("GET")
router.HandleFunc("/synctokenstate/{tokenID}", syncLatestTokenState).Methods("GET")
return router
}