forked from UniverseXYZ/Lobster-Metadata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.go
35 lines (29 loc) · 1.11 KB
/
functions.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
package functions
import (
"net/http"
"os"
"github.com/lobster-metadata/config"
"github.com/lobster-metadata/dlt"
"github.com/lobster-metadata/handlers"
)
func setCORS(w http.ResponseWriter, r *http.Request) (write http.ResponseWriter, response *http.Request) {
// Set CORS headers for the preflight request
if r.Method == http.MethodOptions {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET")
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
w.Header().Set("Access-Control-Max-Age", "3600")
w.WriteHeader(http.StatusNoContent)
return w, r
}
// Set CORS headers for the main request.
w.Header().Set("Access-Control-Allow-Origin", "*")
return w, r
}
func TokenMetadata(w http.ResponseWriter, r *http.Request) {
w, r = setCORS(w, r)
ethClient := dlt.ConnectToEthereum()
contractAddress := os.Getenv("CONTRACT_ADDRESS")
configService := config.NewConfigService("./serverless_function_source_code/config.json")
handlers.HandleMetadataRequest(ethClient, contractAddress, configService)(w, r)
}