简体   繁体   中英

How to run React.js on Scala REST API Server

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?

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM