Hey, I'm trying to use react-admin with a API buil...
# help
s
Hey, I'm trying to use react-admin with a API built on SST. I'm getting this error.
Error: The Content-Range header is missing in the HTTP Response. The simple REST data provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?
I try to pass the requested header on the response. But still i'm getting this error. What did i miss?
Copy code
return {
            statusCode: 200,
            headers: {
                'Content-Type': 'application/json',
                'Content-Range': 'results 0-24/319'
            },
            body: JSON.stringify(results),
        };
f
Hey @Sahan Amadoruge, I think it’s looking for the header for the CORS request. Can you try setting the cors option for the Api like this:
Copy code
new sst.Api(this, "Api", {
  cors: {
    exposeHeaders: ["Content-Range"]
  },
});
s
Thank you @Frank. I'll try this
When i add this. I'm getting CORS error. I then used like this. But still getting the CORS error
Copy code
cors: {
        exposeHeaders: ["Content-Range"],
        allowOrigins: ['*'],
      },
Here's my response from lambda
Copy code
return {
            statusCode: 200,
            headers: {
                'Content-Type': 'application/json',
                'Content-Range': 'results 0-9/319',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Credentials": true,
            },
            body: JSON.stringify(results),
        };
@Frank Any thoughts on this?
f
Sorry, missed ur earlier msg. Can you try
Copy code
import * as apig from "@aws-cdk/aws-apigatewayv2-alpha";

...

cors: {
        exposeHeaders: ["Content-Range"],
        allowHeaders: ["*"],
        allowMethods: [apig.CorsHttpMethod.ANY],
        allowOrigins: ["*"],
      },
s
It's ok. Thanks I'll try this <3
@Frank Thanks. this worked. Is it ok to use a alpha version on a production app?
f
Sorry for the late reply. Yup, it’s been quite stable.
s
Thanks