mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix: support LocalStack-compatible _user_request_ URL for API Gateway execution (#314)
This commit is contained in:
1 parent
8bac81807e
commit
55325eca9a
3 files changed
+203
-1
No files matched your search
+3
-1
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.*;
|
||||
@@ -37,6 +38,7 @@ import java.util.regex.Pattern;
|
||||
* <p>This mirrors the real AWS execute-api URL format:
|
||||
* {@code https://{apiId}.execute-api.{region}.amazonaws.com/{stageName}/{path}}
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@Path("/execute-api/{apiId}/{stageName}")
|
||||
@Produces(MediaType.WILDCARD)
|
||||
public class ApiGatewayExecuteController {
|
||||
@@ -115,7 +117,7 @@ public class ApiGatewayExecuteController {
|
||||
|
||||
// ──────────────────────────── Core dispatch ────────────────────────────
|
||||
|
||||
private Response dispatch(String httpMethod, String apiId, String stageName,
|
||||
Response dispatch(String httpMethod, String apiId, String stageName,
|
||||
String proxy, HttpHeaders headers, UriInfo uriInfo, byte[] body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.*;
|
||||
|
||||
/**
|
||||
* LocalStack-compatible execute endpoint for deployed REST APIs.
|
||||
*
|
||||
* <p>Supports the alternative URL format used by LocalStack and compatible tooling:
|
||||
* {@code /restapis/{apiId}/{stageName}/_user_request_/{proxy+}}
|
||||
*
|
||||
* <p>This is equivalent to the standard execute-api path:
|
||||
* {@code /execute-api/{apiId}/{stageName}/{proxy+}}
|
||||
*/
|
||||
@Path("/restapis/{apiId}/{stageName}/_user_request_")
|
||||
@Produces(MediaType.WILDCARD)
|
||||
public class ApiGatewayUserRequestController {
|
||||
|
||||
private final ApiGatewayExecuteController executeController;
|
||||
|
||||
@Inject
|
||||
public ApiGatewayUserRequestController(ApiGatewayExecuteController executeController) {
|
||||
this.executeController = executeController;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{proxy: .*}")
|
||||
public Response handleGet(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("stageName") String stageName,
|
||||
@PathParam("proxy") String proxy) {
|
||||
return executeController.dispatch("GET", apiId, stageName, proxy, headers, uriInfo, null);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{proxy: .*}")
|
||||
public Response handlePost(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("stageName") String stageName,
|
||||
@PathParam("proxy") String proxy,
|
||||
byte[] body) {
|
||||
return executeController.dispatch("POST", apiId, stageName, proxy, headers, uriInfo, body);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{proxy: .*}")
|
||||
public Response handlePut(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("stageName") String stageName,
|
||||
@PathParam("proxy") String proxy,
|
||||
byte[] body) {
|
||||
return executeController.dispatch("PUT", apiId, stageName, proxy, headers, uriInfo, body);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{proxy: .*}")
|
||||
public Response handleDelete(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("stageName") String stageName,
|
||||
@PathParam("proxy") String proxy) {
|
||||
return executeController.dispatch("DELETE", apiId, stageName, proxy, headers, uriInfo, null);
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@Path("/{proxy: .*}")
|
||||
public Response handlePatch(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("stageName") String stageName,
|
||||
@PathParam("proxy") String proxy,
|
||||
byte[] body) {
|
||||
return executeController.dispatch("PATCH", apiId, stageName, proxy, headers, uriInfo, body);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user