Enabled pprof fly and enable cors at app group in explorer api (#99)
This commit is contained in:
parent
9933fb0d9d
commit
f23f9f78ab
|
@ -147,6 +147,7 @@ func main() {
|
|||
prometheus.RegisterAt(app, "/metrics")
|
||||
app.Use(prometheus.Middleware)
|
||||
|
||||
app.Use(cors.New())
|
||||
app.Use(requestid.New())
|
||||
app.Use(logger.New(logger.Config{
|
||||
Format: "level=info timestamp=${time} method=${method} path=${path} status${status} request_id=${locals:requestid}\n",
|
||||
|
@ -155,9 +156,7 @@ func main() {
|
|||
app.Get("/swagger.json", GetSwagger)
|
||||
|
||||
api := app.Group("/api/v1")
|
||||
api.Use(cors.New()) // TODO CORS restrictions?
|
||||
api.Use(middleware.ExtractPagination)
|
||||
|
||||
api.Get("/health", infrastructureCtrl.HealthCheck)
|
||||
api.Get("/ready", infrastructureCtrl.ReadyCheck)
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ func main() {
|
|||
vaaGossipConsumerSplitter.Start(rootCtx)
|
||||
|
||||
// start fly http server.
|
||||
server := server.NewServer(logger, repository, sqsConsumer, *isLocal)
|
||||
server := server.NewServer(logger, repository, sqsConsumer, *isLocal, true)
|
||||
server.Start()
|
||||
|
||||
go func() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
fiberLog "github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/pprof"
|
||||
"github.com/wormhole-foundation/wormhole-explorer/fly/internal/sqs"
|
||||
"github.com/wormhole-foundation/wormhole-explorer/fly/storage"
|
||||
"go.uber.org/zap"
|
||||
|
@ -16,13 +17,17 @@ type Server struct {
|
|||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewServer(logger *zap.Logger, repository *storage.Repository, consumer *sqs.Consumer, isLocal bool) *Server {
|
||||
func NewServer(logger *zap.Logger, repository *storage.Repository, consumer *sqs.Consumer, isLocal, pprofEnabled bool) *Server {
|
||||
port := os.Getenv("API_PORT")
|
||||
if port == "" {
|
||||
logger.Fatal("You must set your 'API_PORT' environmental variable")
|
||||
}
|
||||
ctrl := NewController(repository, consumer, isLocal)
|
||||
app := fiber.New()
|
||||
// config use of middlware.
|
||||
if pprofEnabled {
|
||||
app.Use(pprof.New())
|
||||
}
|
||||
app.Use(fiberLog.New(fiberLog.Config{
|
||||
Format: "level=info timestamp=${time} method=${method} path=${path} status${status} request_id=${locals:requestid}\n",
|
||||
}))
|
||||
|
|
Loading…
Reference in New Issue