Arpad
05/27/2022, 7:43 AM<http://example.com/api|example.com/api>
to <http://my-api-domain.com/|my-api-domain.com/>
but I'm wondering if there's any plan on adding this to the current static site resources to automate it a bit.Frank
Frank
Frank
<http://example.com/api/users|example.com/api/users>
to <http://my-api-domain.com/users|my-api-domain.com/users>
. The setup in gist redirects <http://example.com/api/users|example.com/api/users>
to <http://my-api-domain.com/api/users|my-api-domain.com/api/users>
which isn’t ideal.Arpad
05/28/2022, 9:14 AMU mean building this into the construct right?Yes, something like:
const site = new sst.ReactStaticSite(stack, "Frontend", {
...
rewrites: {
'api/*': '<http://api.domain.com/:splat|api.domain.com/:splat>' // idea from netlify _redirects file
}
});
For context, right now I am in the process of migrating an old backend from SAM + CloudFormation to SST and we have a Lambda@Edge that handles the rewriting of requests to our backend domain (another guy wrote the code and right now I'm still wrapping my head around everything there). I guess this would be the only way of handling custom rewrites.Arpad
05/28/2022, 9:17 AMexports.handler = async (event) => {
const request = event.Records[0].cf.request;
const newUri = event.Records[0].cf.request.uri.split('/api');
request.uri = newUri[0] + newUri[1];
return request;
}
Pretty basic. It just removes the /api
part from the URL