backend for xcvr appview
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

added websocket routing through nginx

+14 -6
+14 -6
server/cmd/main.go
··· 47 47 http.Error(w, "invalid json", http.StatusBadRequest) 48 48 } 49 49 switch isValidInit(c) { 50 - case ieOK: 51 - c, err = createChannel(c, true) 52 50 case ieNoBand: 53 51 http.Error(w, "must give a band", http.StatusBadRequest) 52 + return 54 53 case ieLongBand: 55 54 http.Error(w, "band must be shorter than 32 bytes", http.StatusBadRequest) 55 + return 56 56 case ieCollision: 57 57 http.Error(w, "band must be unique", http.StatusBadRequest) 58 + return 58 59 case ieLongSign: 59 60 http.Error(w, "sign must be shorter than 51 code points", http.StatusBadRequest) 61 + return 62 + case iePort: 63 + http.Error(w, "should not provide a port", http.StatusBadRequest) 64 + return 65 + case ieOK: 66 + c, err = createChannel(c, true) 67 + } 68 + if err != nil { 69 + http.Error(w, "uh oh", http.StatusTeapot) 60 70 } 61 71 fmt.Printf("created a channel on band: %s and call sign: %s\n", c.Band, c.Sign) 62 72 encoder := json.NewEncoder(w) ··· 74 84 iePort 75 85 ) 76 86 77 - //TODO: can changes to bandToServer after unlock create data race? 87 + // TODO: can changes to bandToServer after unlock create data race? 78 88 func isValidInit(c channel) initError { 79 89 if c.Band == "" { 80 90 return ieNoBand ··· 114 124 c.Port = port 115 125 116 126 options := []lrcd.Option{lrcd.WithWSPort(c.Port), 117 - lrcd.WithWSPath(c.Band), 118 127 lrcd.WithWelcome(c.Sign), 119 128 lrcd.WithLogging(os.Stdout, true), 120 129 } ··· 171 180 return (nl.Addr().(*net.TCPAddr)).Port, nil 172 181 } 173 182 174 - 175 183 func withCORSAll(h http.Handler) http.Handler { 176 - return http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) { 184 + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 177 185 fmt.Println("incoming request:", r.Method, r.URL.Path) 178 186 w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173") 179 187 w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")