Mobygo
Mobygo

Reputation: 61

React app Failed to load resource: the server responded with a status of 404

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.

Upvotes: 0

Views: 5954

Answers (1)

DINK74
DINK74

Reputation: 547

have you set homepage variable in package.json?

{
  "homepage": "./"
}

Upvotes: 0

Related Questions