2022-05-11 18:47:31 -04:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2022-11-07 19:03:45 -05:00
|
|
|
"time"
|
2022-05-11 18:47:31 -04:00
|
|
|
|
|
|
|
"npm/internal/logger"
|
2023-03-07 01:42:26 -05:00
|
|
|
"npm/internal/serverevents"
|
2022-05-11 18:47:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const httpPort = 3000
|
|
|
|
|
|
|
|
// StartServer creates a http server
|
|
|
|
func StartServer() {
|
|
|
|
logger.Info("Server starting on port %v", httpPort)
|
2022-11-07 19:03:45 -05:00
|
|
|
|
|
|
|
server := &http.Server{
|
|
|
|
Addr: fmt.Sprintf(":%v", httpPort),
|
|
|
|
Handler: NewRouter(),
|
|
|
|
ReadHeaderTimeout: 3 * time.Second,
|
|
|
|
}
|
|
|
|
|
2023-03-07 01:42:26 -05:00
|
|
|
defer serverevents.Shutdown()
|
|
|
|
|
2022-11-07 19:03:45 -05:00
|
|
|
err := server.ListenAndServe()
|
2022-05-11 18:47:31 -04:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("HttpListenError", err)
|
|
|
|
}
|
|
|
|
}
|