我已经创建了一个ReactJS并使用webpack构建其包。现在,我希望从没有太多可用资源的嵌入式计算机上为它提供服务。
因此,我决定构建一个快速静态服务器。我的项目还有另一个在端口3001上运行API的服务器。这是我的静态服务器代码:
const express = require("express");
const path = require("path");
const port = process.env.PORT || 80;
const proxy = require("http-proxy-middleware");
const morgan = require("morgan");
const app = express();
// logger (see morgan codes)
app.use(
morgan(
':date[clf] (:response-time ms) :remote-addr - :remote-user ":method :url HTTP/:http-version" :status :res[content-length] bytes'
)
);
// this assumes that all your app files
// `public` directory relative to where your server.js is
app.use(express.static(__dirname + "/static"));
// API calls are redirected to the API Server on port 3001
app.use(
["/status", "/login", "/reboot", "/reset", "/changepassword", "/graphql"],
proxy({ target: "http://localhost:3001", changeOrigin: true })
);
app.get("*", function(request, response) {
response.sendFile(path.resolve(__dirname, "index.html"));
});
app.listen(port);
console.log("Page server started on port " + port);
运行它,日志中显示以下内容:
[HPM] Proxy created: / -> http://localhost:3001
Page server started on port 8080
21/Jun/2018:00:23:01 +0000 (5.251 ms) ::1 - - "GET / HTTP/1.1" 304 - bytes
21/Jun/2018:00:23:01 +0000 (1.085 ms) ::1 - - "GET /static/css/main.3fc8ac40.css HTTP/1.1" 304 - bytes
21/Jun/2018:00:23:01 +0000 (1.168 ms) ::1 - - "GET /static/js/main.b300fb14.js HTTP/1.1" 304 - bytes
21/Jun/2018:00:23:01 +0000 (0.324 ms) ::1 - - "GET /favicon.ico HTTP/1.1" 304 - bytes
21/Jun/2018:00:23:21 +0000 (0.408 ms) ::1 - - "GET /static/css/main.3fc8ac40.css HTTP/1.1" 304 - bytes
因此,我的包正在提供中,但是我的ReactJS应用程序未显示在屏幕上(我得到的是空字符串)。
我的服务器上缺少什么让我可以浏览屏幕?