API Gateway/Cloudfront redirects folder access from express app which will return the index.html

0

I have a serverless app running fine on API Gateway and CloudFront using express. The problem occurs when accessing a folder with an index.html file - it gets redirected to itself in a loop.

Main app working fine here: https://d2x40omue01gmu.cloudfront.net/

Click on blog link in header and it should eventually go to: https://d2x40omue01gmu.cloudfront.net/blog/

But it gets redirected back to itself. This is a CloudFront for an API Gateway endpoint

The express app handles GET on /blog* by returning express.static(browserFolder, { maxAge: '1m' }))

This works fine locally and on Firebase serverless: https://www.findrvparks.com/blog/

Any help appreciated

2개 답변
0
수락된 답변

Turns out that running the express app on API Gateway in a subfolder means I have to add the /prod prefix to the express get handler as /prod/blog*

답변함 2년 전
0

Your API Gateway is returning 301 redirects on requests for /blog to /blog/

Requests for /blog/ result in a 403 which I believe is the correct behavior. However, this isn't the case for (eg) /maps - that just returns a 403 immediately, not a redirect to /maps/

I think the problem is that CloudFront has cached the 301 response for /blog and is serving it for subsequent requests for /blog/

To solve this, the best option would be to remove the direct from /blog to /blog/ if possible. Once you've done that, you'll need to invalidate /blog in the CloudFront cache.

AWS
전문가
Paul_L
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠