MCPcopy
hub / github.com/apache/devlake / SetupApiServer

Function SetupApiServer

backend/server/api/api.go:114–160  ·  view source on GitHub ↗
(router *gin.Engine)

Source from the content-addressed store, hash-verified

112}
113
114func SetupApiServer(router *gin.Engine) {
115 // Set gin mode
116 gin.SetMode(basicRes.GetConfig("MODE"))
117 // Required for `/projects/hello%20%2F%20world` to be parsed properly with `/projects/:projectName`
118 // end up with `name = "hello / world"`
119 router.UseRawPath = true
120 // router.UnescapePathValues = false
121
122 // Endpoint to proceed database migration
123 router.GET("/proceed-db-migration", func(ctx *gin.Context) {
124 // Execute database migration
125 errors.Must(services.ExecuteMigration())
126 // Return success response
127 shared.ApiOutputSuccess(ctx, nil, http.StatusOK)
128 })
129
130 // Restrict access if database migration is required
131 router.Use(func(ctx *gin.Context) {
132 serviceStatus := services.CurrentStatus()
133 if serviceStatus == services.SERVICE_STATUS_WAIT_CONFIRM {
134 // Return error response
135 shared.ApiOutputError(
136 ctx,
137 errors.HttpStatus(http.StatusPreconditionRequired).New(DB_MIGRATION_REQUIRED),
138 )
139 ctx.Abort()
140 } else if serviceStatus == services.SERVICE_STATUS_MIGRATING {
141 // Return error response
142 shared.ApiOutputError(
143 ctx,
144 errors.HttpStatus(http.StatusPreconditionRequired).New(DB_MIGRATING),
145 )
146 ctx.Abort()
147 }
148 })
149
150 // Add swagger handlers
151 router.GET("/swagger/*any", modifyBasePath, ginSwagger.WrapHandler(swaggerFiles.Handler))
152 registerExtraOpenApiSpecs(router)
153
154 // Add debug logging for endpoints
155 gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {
156 logruslog.Global.Printf("endpoint %v %v %v %v", httpMethod, absolutePath, handlerName, nuHandlers)
157 }
158 // Register API endpoints
159 RegisterRouter(router, basicRes)
160}
161
162func RunApiServer(router *gin.Engine) {
163 // Get port from config

Callers 1

CreateAndRunApiServerFunction · 0.85

Calls 5

RegisterRouterFunction · 0.85
GetConfigMethod · 0.65
NewMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected