| 158 | } |
| 159 | |
| 160 | func (s *RPCEndPointServer) startMainServer() { |
| 161 | if s.server != nil { |
| 162 | panic("http server is already running") |
| 163 | } |
| 164 | // Handler for root URL (JSON-RPC on POST, public/index.html on GET) |
| 165 | mux := http.NewServeMux() |
| 166 | mux.HandleFunc("/", s.HandleHTTPRequest) |
| 167 | mux.HandleFunc("/health", s.handleHealthRequest) |
| 168 | mux.HandleFunc("/bundle", s.HandleBundleRequest) |
| 169 | s.server = &http.Server{ |
| 170 | Addr: s.listenAddress, |
| 171 | Handler: mux, |
| 172 | WriteTimeout: 30 * time.Second, |
| 173 | ReadTimeout: 30 * time.Second, |
| 174 | } |
| 175 | go func() { |
| 176 | if err := s.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { |
| 177 | s.logger.Error("http server failed", zap.Error(err)) |
| 178 | } |
| 179 | }() |
| 180 | } |
| 181 | |
| 182 | func (s *RPCEndPointServer) stopMainServer() { |
| 183 | if s.server != nil { |