How can I redirect to static javascript app from subfolder in a Node.js app on Heroku?

Viewed 298

I have a static javascript app built in React that I've deployed to firebase, and lives at example.firebaseapp.com.

I also have a Node app that serves my main application at www.example.com and is hosted on Heroku.

What I'm trying to figure out is, how do I have the user visit to my static javascript application when visiting a given subfolder, e.g. www.example.com/app?

Also, is there a way to do this where I'm not having to deal with CORS issues since they will essentially live on the same domain?

1 Answers

use nginx on the server that serves the main application. by this way you will not have cors problem neither the user will feel that he's being served on different domain.

you can start with this nginx config:

location / {
  proxy_set_header   X-Real-IP $remote_addr;
  proxy_set_header   Host      $http_host;
  proxy_pass         http://YOURTOMCATSERVER:{PORT};
}

location /blog {
  proxy_set_header   X-Real-IP $remote_addr;
  proxy_set_header   Host      $http_host;
  proxy_pass         http://YOURBLOGSERVER:{PORT};
}
Related