Skip to content

Commit 4276b56

Browse files
committed
handle wsl port forwarding
1 parent 8ccc01e commit 4276b56

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmd/login.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ func cors(next http.Handler) http.Handler {
149149
})
150150
}
151151
func startHTTPServer(inputChan chan string) {
152-
handleSubmit := func(res http.ResponseWriter, req *http.Request) {
153-
code, err := io.ReadAll(req.Body)
152+
handleSubmit := func(w http.ResponseWriter, r *http.Request) {
153+
code, err := io.ReadAll(r.Body)
154154
if err != nil {
155155
return
156156
}
@@ -159,12 +159,18 @@ func startHTTPServer(inputChan chan string) {
159159
fmt.Print("\n\033[1A\033[K")
160160
}
161161

162-
handleHealth := func(res http.ResponseWriter, req *http.Request) {
162+
handleHealth := func(w http.ResponseWriter, r *http.Request) {
163163
// 200 OK
164164
}
165165

166+
handleRedirect := func(w http.ResponseWriter, r *http.Request) {
167+
loginUrl := viper.GetString("frontend_url") + "/cli/login"
168+
http.Redirect(w, r, loginUrl, http.StatusSeeOther)
169+
}
170+
166171
http.Handle("POST /submit", cors(http.HandlerFunc(handleSubmit)))
167172
http.Handle("/health", cors(http.HandlerFunc(handleHealth)))
173+
http.Handle("/{$}", cors(http.HandlerFunc(handleRedirect)))
168174

169175
// if we fail, oh well. we fall back to entering the code
170176
_ = http.ListenAndServe("localhost:9417", nil)

0 commit comments

Comments
 (0)