skip to Main Content

I am trying to run a React app under Plesk Windows hosting. The React app was created by the command create-react-app.

I created a static assets directory called build with the command npm run build.

I created a file called server.js in the project root directory with the following content:

const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));

app.get('/', function (req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

app.listen(process.env.PORT);

Under Plesk Node.js, the application startup script is set to start with this file server.js.

When running the app in the browser and inspecting the debug output, console logging is as follows:

Failed to load resource: the server responded with a status of 404 () main.2cadfda6.css:1
Failed to load resource: the server responded with a status of 404 () main.c6034903.js:1
Failed to load resource: the server responded with a status of 404 () /favicon.ico:1
Failed to load resource: the server responded with a status of 404 () manifest.json:1
Manifest: Line: 1, column: 1, Syntax error. manifest.json:1
Failed to load resource: the server responded with a status of 404 () main.2cadfda6.css:1
Failed to load resource: the server responded with a status of 404 () manifest.json:1

and a white page is getting displayed.

The app is running fine when issuing the command serve -s build in a terminal.

2

Answers


  1. have you set homepage variable in package.json?

    {
      "homepage": "./"
    }
    
    Login or Signup to reply.
  2. In my case the issue was I was serving my react project from a build folder and there was /build in .gitignore file. I removed /build from .gitignore file and it worked

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search