anie
anie

Reputation: 519

Deploying full stack app to digital ocean not serving the frontend from the express server

I am deploying my app to digitalOcean using App Platfrom, My app structure as follow:

 client
       ├── /public
       ├── /src
       ├── package-lock.json
       └── package.json

 index.js // this the index of the express server 
 routes
       └── api.js
 package-lock.json
 package.json

The client folder is the react app and the root folder is the express server. I have followed this tutorial on how to deploy express server that include react app by serving react files from express server using:

app.use(express.static(path.join(__dirname, 'client/build')));

which included in index.js file in root directory. when i deployed the app to heroku everything was fine as react frontend is been served by the server from client folder and backend api working fine, but i want to deploy it to digitalocean instead,so the important part is defining the scripts in packages.json in root directory which will looks like:

"scripts": {
  "start": "node index.js",
  "digitalocean-build": "cd client && npm install && npm run build"
}

but as in digitalocean when configure the app before deployment there is two options provided

Build Command // i used here npm run digitalocean-build

Run Command  //i used  npm run  start

After deployment done when i check the url only the server index is running but not both the server and react frontend. I have been struggling in this for almost two days and I'm sure there is something I haven't cover it yet. i will really appreciate any help.

Upvotes: 1

Views: 582

Answers (1)

DragonKnight
DragonKnight

Reputation: 1

Try this one as a build command.

npm i && npm --prefix frontend install && npm --prefix frontend run build

Upvotes: 0

Related Questions