-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
we are using remix-aws but i need to send analytics events for all requests (even non rendering routes) so i had to rip the code from this repo and uninstall remix-aws and just use the modified code.
would be nice if we could still use remix-aws instead tho. please add the ability to modify the request handler or inject a callback or something.
this is the modified version of the createRequestHandler that we are using. we basically just wrapped an analytics event around the request object before the response
export function createRequestHandler({
build,
getLoadContext,
mode = process.env.NODE_ENV,
awsProxy = AWSProxy.APIGatewayV2,
}: {
build: ServerBuild;
getLoadContext?: GetLoadContextFunction;
mode?: string;
awsProxy?: AWSProxy;
}): RequestHandler {
const handleRequest = createRemixRequestHandler(build, mode);
return async (
event:
| APIGatewayProxyEvent
| APIGatewayProxyEventV2
| ALBEvent /*, context*/,
) => {
const awsAdapter = createRemixAdapter(awsProxy);
const request = awsAdapter.createRemixRequest(
event as APIGatewayProxyEvent & APIGatewayProxyEventV2 & ALBEvent,
);
const loadContext = getLoadContext?.(event);
// analytics
let newRequest = request;
try {
newRequest = await sendServerEvents(request);
} catch (e) {
// do nothing
console.log("ANALYTICS SERVER ERROR");
console.error(e);
}
const response = (await handleRequest(newRequest, loadContext)) as Response;
return awsAdapter.sendRemixResponse(response);
};
}
Metadata
Metadata
Assignees
Labels
No labels