0

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?

5
  • 1
    Actually 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. Commented Jun 1, 2018 at 14:30
  • You mean separate client side and server side on different port? Commented Jun 1, 2018 at 14:32
  • 1
    Yes!! That’s what I mean Commented Jun 1, 2018 at 14:47
  • Thank. What do you mean about S3 for react builded files (html, css, js)? Commented Jun 1, 2018 at 16:36
  • Sorry I don’t know about it Commented Jun 1, 2018 at 16:52

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.