@@ -54,7 +54,16 @@ Press Ctrl+C to stop the server
5454
5555` , port )
5656
57- log .Fatal (http .ListenAndServe (":" + port , corsMiddleware (mux )))
57+ // Create server with proper timeout configuration
58+ srv := & http.Server {
59+ Addr : ":" + port ,
60+ Handler : corsMiddleware (mux ),
61+ ReadTimeout : 15 * time .Second ,
62+ WriteTimeout : 15 * time .Second ,
63+ IdleTimeout : 60 * time .Second ,
64+ }
65+
66+ log .Fatal (srv .ListenAndServe ())
5867}
5968
6069func corsMiddleware (next http.Handler ) http.Handler {
@@ -74,7 +83,10 @@ func corsMiddleware(next http.Handler) http.Handler {
7483
7584func handleIndex (w http.ResponseWriter , r * http.Request ) {
7685 tmpl := template .Must (template .New ("index" ).Parse (indexHTML ))
77- tmpl .Execute (w , nil )
86+ if err := tmpl .Execute (w , nil ); err != nil {
87+ http .Error (w , err .Error (), http .StatusInternalServerError )
88+ return
89+ }
7890}
7991
8092func handleDecode (w http.ResponseWriter , r * http.Request ) {
@@ -242,22 +254,25 @@ func tryDecodeSignedData(data []byte) interface{} {
242254 }
243255
244256 // Add DACommitment hash
245- dataHash := signedData .Data . DACommitment ()
257+ dataHash := signedData .DACommitment ()
246258 result ["dataHash" ] = bytesToHex (dataHash [:])
247259
248260 return result
249261}
250262
251263func bytesToHex (b []byte ) string {
252- if b == nil || len (b ) == 0 {
264+ if len (b ) == 0 {
253265 return ""
254266 }
255267 return hex .EncodeToString (b )
256268}
257269
258270func sendJSONResponse (w http.ResponseWriter , data interface {}) {
259271 w .Header ().Set ("Content-Type" , "application/json" )
260- json .NewEncoder (w ).Encode (data )
272+ if err := json .NewEncoder (w ).Encode (data ); err != nil {
273+ http .Error (w , err .Error (), http .StatusInternalServerError )
274+ return
275+ }
261276}
262277
263278func min (a , b int ) int {
0 commit comments