简体   繁体   English

如何在Scala REST API服务器上运行React.js

[英]How to run React.js on Scala REST API Server

I have React.js app which I created using create-react-app. 我有使用create-react-app创建的React.js应用程序。 Also I have Scala REST API which use Akka-HTTP. 我也有使用Akka-HTTP的Scala REST API。 For build React app I use npm run build . 对于构建React应用程序,我使用npm run build I want that Scala send on client index.html with other static file. 我希望Scala将客户端index.html与其他静态文件一起发送。 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. 使用Nginx。 Serve the static npm-built files with that. 以此为静态npm生成的文件提供服务。 Forward API requests to the scala app. 将API请求转发到scala应用。 Minimal example nginx config using URL path prefix to separate static and api. 使用URL路径前缀分隔静态和api的最小示例nginx配置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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