简体   繁体   中英

Request headers with S3 static website hosting React app with CloudFront

I have a React app deployed to S3 with a CloudFront distribution on top of it for a specific domain CNAME. I want to be able to create a second CloudFront distribution for a separate, different domain but use the same S3 bucket as the origin.

However, in the React app I need to be able to know where the request came from so that the app can dynamically load different data based on that. I found that I can pass on a custom HTTP header from CloudFront to the origin, but that doesn't seem to be accessible from the React code that gets run in the browser.

Is there a way to do this with S3 and CloudFront?

I would recommend using React Router to handle rendering different components / data based on the route - the docs are quite excellent. I have a React app hosted in S3 behind a CF distribution using React Router and it works excellently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM