1

I'm not very familiar with deployment and networking as I'm primarily a frontend developer. I want to create a project with Laravel and React (separated, not integrated with blade), and deploy them to AWS. I want to use Laravel only as an API server, and I'm planning to deploy it on EC2. If I host my React app on S3, how will it be possible for me to share the same domain with the API sever running on the EC2 instance?

I know that I can have separate subdomains,like www.example.com for my React app and api.example.com for my API server. However, if I want to have www.example.com for my React app and www.example.com/api for my API server, what options do I have? And what resources can you recommend for me to get more up to speed on this topic? Thanks!

Soo Hwan Kim
  • 83
  • 1
  • 6

1 Answers1

6

As you want to use S3 and EC2 you would need to use a service that can distribute to both endpoints based on a condition.

The best service for this would be CloudFront, which supports distribution to S3 and EC2 (as a custom origin).

To do this you would create your distribution with an origin for the S3 bucket, and an origin for the API. As your API is hosted on the /api/* path you would add this as the path pattern when adding the secondary origin via a behaviour.

CloudFront will then route any requests to /api/* paths to your EC2 origin.

I have found an article named How to route to multiple origins with CloudFront which I hope will explain the steps to accomplish this in greater detail.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • Thanks Chris! Your response was very helpful, I read the article that you linked, and I'll look more into how CloudFront would be able to help me with what I need. Thanks again! :) – Soo Hwan Kim Aug 08 '20 at 09:39