This question is not going to be particularly loaded with detail, because the problem is very basic, and pertains to the limitations in how Plesk Onyx implements Node support.
I'm trying to deploy a react app created with create-react-app to a domain hosted on a server with Plesk Onyx installed. I obviously cannot mess around with the core server because I might break other domains. So I need to install this app in a manner that is handled properly by Plesk. The problem I'm having is that I'm not finding a guide for how to do this anywhere.
Plesk requires a project structure that is really quite inflexible, and it's nothing like the structure imposed by create-react-app. For instance, Plesk requires that the document root be a child of the application root, which is the complete inverse of the way create-react-app sets up a project.
I have not shown code here because it's a deployment issue, not a code issue, and involves the structure of projects and how to shove a round peg into a square hole.
Create a . htaccess file to your public folder in your create-react-app folder. Then build your app using npm run build.
I've had a similar problem but I think I have some kind of a workaround. I haven't actually tried if this works or in Plesk Onyx or not.
Basically I wanted to put a create-react-app to a plesk onyx based hosting and run npm start
which eventually leads to react-scripts start
, and I realized that Plesk doesn't have the capability to do that. Plesk isn't a VPS...
Instead, Plesk runs a js script file to execute the server, like App.js
or server.js
and it can be set through the Plesk NodeJS control panel.
To do that, I installed express
by running:
npm install express --save
and made a server.js
file which contains this code:
const express = require('express');
const bodyParser = require('body-parser')
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 || 8080);
I got the code from here: https://dev.to/loujaybee/using-create-react-app-with-express
Then I run npm run build
to create a production build, and finally node server.js
. My app (a simple tic-tac-toe game from the react tutorial) is available in localhost port 8080.
The root page
I'll give you an update if I did succeed.
I found a really easy was to do this without adding express or using node. This will also make react-router
work.
.htaccess
file to your public
folder in your create-react-app
folderOptions -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html [QSA,L]
npm run-script build
build
directory to your Linux server on PleskIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With