diff --git a/backend/aws/dynamodb.go b/backend/aws/dynamodb.go index 9b7bac4..98ab929 100644 --- a/backend/aws/dynamodb.go +++ b/backend/aws/dynamodb.go @@ -349,15 +349,13 @@ func (e DynamoTableRecords[T]) QueryBatch(querys []DynamoQueryParam) ([]T, error output, err := client.Query(context.TODO(), &queryInput) if err != nil { - core.Log("Error al ejecutar la DynamoDB") - panic(err) + return nil, core.Err("Error al ejecutar la query:", err) } items := []DynamoDBItem{} err = attributevalue.UnmarshalListOfMaps(output.Items, &items) if err != nil { - core.Log("Error al deserializar Dynamodb: " + err.Error()) - return nil, err + return nil, core.Err("Error al deserializar DynamoDB:", err) } for _, dynamoItem := range items { diff --git a/backend/core/responses.go b/backend/core/responses.go index b9c818a..987a0f4 100644 --- a/backend/core/responses.go +++ b/backend/core/responses.go @@ -12,6 +12,7 @@ import ( "io" "log" "net/http" + "net/url" "os" "runtime" "strconv" @@ -21,6 +22,7 @@ import ( "github.com/andybalholm/brotli" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi" + smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/gorilla/websocket" ) @@ -56,13 +58,21 @@ func PrintMemUsage() { var apiClient *apigatewaymanagementapi.Client +type endpointResolverV2 struct{} + +func (r endpointResolverV2) ResolveEndpoint(ctx context.Context, params apigatewaymanagementapi.EndpointParameters) (smithyendpoints.Endpoint, error) { + uri, _ := url.Parse("https://pv5s7gfoge.execute-api.us-east-1.amazonaws.com/p/") + return smithyendpoints.Endpoint{URI: *uri}, nil +} + func MakeAPIGatewayClient() *apigatewaymanagementapi.Client { if apiClient == nil { awsCfg := GetAwsConfig() options := apigatewaymanagementapi.Options{ - Credentials: awsCfg.Credentials, - Region: awsCfg.Region, + Credentials: awsCfg.Credentials, + Region: awsCfg.Region, + EndpointResolverV2: endpointResolverV2{}, } apiClient = apigatewaymanagementapi.New(options) diff --git a/backend/main.go b/backend/main.go index 17b845a..38880ec 100644 --- a/backend/main.go +++ b/backend/main.go @@ -48,6 +48,9 @@ func LambdaHandler(_ context.Context, request *core.APIGatewayV2HTTPRequest) (*e response := core.MainResponse{} // Revisa si es websocket if core.Contains(wssEvents, args.EventType) { + if args.EventType != "MESSAGE" { + return &events.APIGatewayProxyResponse{StatusCode: 200, Body: "OK"}, nil + } fmt.Println("Parseando websocket:: ", args.ConnectionID) awsArgs := ParseWssMessage([]byte(request.Body)) args.Body = awsArgs.Body @@ -161,18 +164,6 @@ func ParseWssMessage(messageRaw []byte) core.HandlerArgs { } } -// Handler principal (para lambda y para local) -func WssHandler(args core.HandlerArgs) core.MainResponse { - - fmt.Println("Respondiendo status 200 Connected") - return core.MainResponse{ - LambdaResponse: &events.APIGatewayV2HTTPResponse{ - StatusCode: 200, - Body: "Connected", - }, - } -} - func OnPanic(panicMessage interface{}) { core.Logx(5, "Error 500 (Panic): ", panicMessage) core.Log(string(debug.Stack())) diff --git a/deploy.sh b/deploy.sh index eb27211..37e4879 100755 --- a/deploy.sh +++ b/deploy.sh @@ -34,7 +34,7 @@ if [[ $ACCIONES == *"2"* ]]; then cd ./cloud go run . accion=1 - echo "El deploy backend-node finalizado!" + echo "El deploy backend finalizado!" fi