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.
4
Answers
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 toreact-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
orserver.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: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 finallynode 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.
Valian’s workaround does indeed work for SPAs. However if you are using react-router to create a multipage app, it is an easy fix.
You need to add an additional app.get() with a wildcard to cover all of your paths.
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 yourpublic
folder in yourcreate-react-app
foldernpm run-script build
build
directory to your Linux server on Pleskmy work around for this issue is
upload your code .
run Npm install
run this from run-script option:
build
after that set your Document Root to http://your-URL.com/build like
this
this worked for me .