I have React.js app which I created using create-react-app. Also I have Scala REST API which use Akka-HTTP. For build React app I use npm run build. I want that Scala send on client index.html with other static file. I started writing routes for static files, but this method has long been used and can today have something else to do it automatically. Can you advise me how to solve this problem?
-
1Actually the problem you gonna face is cors issue!! Which is you have two service running and they want to communicate to each other for that I would suggest you to use nginx.Raman Mishra– Raman Mishra2018-06-01 14:30:11 +00:00Commented Jun 1, 2018 at 14:30
-
You mean separate client side and server side on different port?Виталий Мудрый– Виталий Мудрый2018-06-01 14:32:31 +00:00Commented Jun 1, 2018 at 14:32
-
1Yes!! That’s what I meanRaman Mishra– Raman Mishra2018-06-01 14:47:14 +00:00Commented Jun 1, 2018 at 14:47
-
Thank. What do you mean about S3 for react builded files (html, css, js)?Виталий Мудрый– Виталий Мудрый2018-06-01 16:36:51 +00:00Commented Jun 1, 2018 at 16:36
-
Sorry I don’t know about itRaman Mishra– Raman Mishra2018-06-01 16:52:51 +00:00Commented Jun 1, 2018 at 16:52
Add a comment
|
1 Answer
Use Nginx. Serve the static npm-built files with that. Forward API requests to the scala app. Minimal example nginx config using URL path prefix to separate static and api.
upstream server-api {
server localhost:9000;
}
server {
listen 80;
server_name _;
location /api {
proxy_pass http://server-api;
}
location / {
root /usr/share/nginx/dist;
index index.html index.htm;
}
}