-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go.legacy
More file actions
66 lines (52 loc) · 1.81 KB
/
Copy pathmain.go.legacy
File metadata and controls
66 lines (52 loc) · 1.81 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
56
57
58
59
60
61
62
63
64
65
66
// package main
// import (
// "crypto/hmac"
// "crypto/sha1"
// "encoding/json"
// "fmt"
// "net/http"
// "time"
// "github.com/gorilla/handlers"
// "github.com/gorilla/mux"
// )
// const (
// turnStaticAuthSecret = "supersecuresecret" // TURN 서버의 static-auth-secret
// turnRealm = "yourdomain.com" // TURN 서버의 realm
// )
// type TurnCredentials struct {
// Username string `json:"username"`
// Credential string `json:"credential"`
// Realm string `json:"realm"`
// }
// func generateTurnCredentials() TurnCredentials {
// timestamp := time.Now().Unix()
// username := fmt.Sprintf("%d", timestamp)
// // Generate HMAC-SHA1 credential using the static-auth-secret
// credential := fmt.Sprintf("%x", hmacSHA1(turnStaticAuthSecret, username))
// return TurnCredentials{
// Username: username,
// Credential: credential,
// Realm: turnRealm,
// }
// }
// func hmacSHA1(secret, message string) []byte {
// // Use HMAC-SHA1 to generate the credential
// h := hmac.New(sha1.New, []byte(secret))
// h.Write([]byte(message))
// return h.Sum(nil)
// }
// func turnHandler(w http.ResponseWriter, r *http.Request) {
// credentials := generateTurnCredentials()
// w.Header().Set("Content-Type", "application/json")
// json.NewEncoder(w).Encode(credentials)
// }
// func main() {
// router := mux.NewRouter()
// // Define the TURN endpoint
// router.HandleFunc("/turn", turnHandler).Methods("GET")
// // Add CORS middleware
// corsAllowedOrigins := handlers.AllowedOrigins([]string{"http://localhost:3000"}) // React 앱 주소
// corsAllowedMethods := handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS"})
// fmt.Println("Server running at http://localhost:8080")
// http.ListenAndServe(":8080", handlers.CORS(corsAllowedOrigins, corsAllowedMethods)(router))
// }