fix: Fixes API routes.

This commit is contained in:
Tera << 8 2024-12-23 20:47:01 -05:00
parent fe8980b265
commit bcf97fde6d
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
15 changed files with 284 additions and 132 deletions

View file

@ -19,10 +19,6 @@ type ProxyStartRequest struct {
ID uint `validate:"required" json:"id"`
}
type ProxyStartResponse struct {
Success bool `json:"success"`
}
func StartProxy(c *gin.Context) {
var req ProxyStartRequest
@ -92,9 +88,19 @@ func StartProxy(c *gin.Context) {
return
}
backend := backendruntime.RunningBackends[proxy.BackendID]
backend, ok := backendruntime.RunningBackends[proxy.BackendID]
backend.RuntimeCommands <- commonbackend.AddProxy{
if !ok {
log.Warnf("Couldn't fetch backend runtime from backend ID #%d", proxy.BackendID)
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Couldn't fetch backend runtime",
})
return
}
backend.RuntimeCommands <- &commonbackend.AddProxy{
Type: "addProxy",
SourceIP: proxy.SourceIP,
SourcePort: proxy.SourcePort,
@ -121,13 +127,19 @@ func StartProxy(c *gin.Context) {
return
}
break
default:
log.Errorf("Got illegal response type for backend #%d: %T", proxy.BackendID, responseMessage)
break
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Got invalid response from backend. Proxy was still successfully deleted",
})
return
}
c.JSON(http.StatusOK, &ProxyStartResponse{
Success: true,
c.JSON(http.StatusOK, gin.H{
"success": true,
})
}