Routing problems after the release of React + express

write a simple DEMO,create-react-app + Express background access database, react front-end display. The development environment is running normally.

the server release environment is also very simple, with node 10.9. After, npm run build according to the online method, put the build folder under the public of the server code. Copy it to the node 10.9 server, run the localhost:3001 blank page, and the routing will not be configured.

build

app.js

var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");

var indexRouter = require("./routes/index");
var usersRouter = require("./routes/supplies");

var app = express();

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", indexRouter);
app.use("/supplies", usersRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

index.js

var express = require("express");
var router = express.Router();

/* GET home page. */

router.get("/", function(req, res, next) {
  //res.render("index", { title: "Express" });
  console.log("hello will!");
  //path.resolve(__dirname,"../public/build/index.html")
  res.sendFile("E:/www/react-backend/public/build/index.html");
});

module.exports = router;

localhost:3001 blank,
server output
hello will!
[0mGET / [36m304 [0m0.620 ms-- [0m
] [0mGET / static/css/main.0d5ac3e0.css [33m404 [0m10.199 ms-1022 [0m
] [0mGET / static/js/main.ceae68dd.js [0m18.856 ms-1022 [0m

]

debugging found that
failed to load < script > pointing to " http://localhost:3001/static/js/main.ceae68dd.js ".


add homepage to packge.json . If the last publishing address is the server root path, then configure homepage:' http://localhost:3001', and repackage it. It should be fine

.
Menu