How to deploy react application in a sub-directory using AWS Load Balancer

Viewed 426

I have been trying to run my react application on a subdirectory . I am using a load balancer (ALB) to and redirecting my application on "directory" from "https://mydomain/directory". But static file of the build was not being found by my application

added direcctory on package.json. "homepage": "/directory" added basename on react-router-dom in my networks index.html is looking for ".#####/directory/static/js" and css in the same way

i am only able to run my react build by redirecting static request to my react build, but this is not the good solution because i want to run 3 applications on my ALB and this will cause me change my assets folder name manually in the build, obviously don't want to do that. I have been applying multiple solutions but couldn't find a proper solution please someone help in this.

2 Answers

ALB doesn't do redirects, and it doesn't do any sort of request path rewriting, it simply forwards the request to the target. You need to setup your server so it is actually serving the website from that folder, in other words change your assets folder name in the build.

If you don't want to do that, you would need to look at other AWS solutions like CloudFront which can proxy the request to a different path on the origin server.

Related