MCPcopy Index your code
hub / github.com/bootdotdev/bootdev / startHTTPServer

Function startHTTPServer

cmd/login.go:110–136  ·  view source on GitHub ↗
(inputChan chan string)

Source from the content-addressed store, hash-verified

108}
109
110func startHTTPServer(inputChan chan string) {
111 handleSubmit := func(w http.ResponseWriter, r *http.Request) {
112 code, err := io.ReadAll(r.Body)
113 if err != nil {
114 return
115 }
116 inputChan <- string(code)
117 // Clear current line
118 fmt.Print("\n\033[1A\033[K")
119 }
120
121 handleHealth := func(w http.ResponseWriter, r *http.Request) {
122 // 200 OK
123 }
124
125 handleRedirect := func(w http.ResponseWriter, r *http.Request) {
126 loginURL := viper.GetString("frontend_url") + "/cli/login"
127 http.Redirect(w, r, loginURL, http.StatusSeeOther)
128 }
129
130 http.Handle("POST /submit", cors(http.HandlerFunc(handleSubmit)))
131 http.Handle("/health", cors(http.HandlerFunc(handleHealth)))
132 http.Handle("/{$}", cors(http.HandlerFunc(handleRedirect)))
133
134 // if we fail, oh well. we fall back to entering the code
135 _ = http.ListenAndServe("localhost:9417", nil)
136}
137
138func init() {
139 rootCmd.AddCommand(loginCmd)

Callers 1

login.goFile · 0.85

Calls 1

corsFunction · 0.85

Tested by

no test coverage detected