I have a code base that looks as follows:
rootfolder
-- backend
-- frontend
-- .git
the .git folder hence the entire version control is located in rootfolder, each subfolder (backend and frontend) has a package.json and a package.lock file
the backend project is a NestJs App
the fronted project is an Angular App
in order to serve the client files I've designated / route of my backend app to serve static files, those files are the compiled version of my frontend
in localhost it works like a charm, the thing comes when deploying to Heroku
I have CI/CD pipelines that automate this task but they fail because Heroku cant detect a package.json file in rootfolder
I would just need to run my server (inside backend folder) to spin up my entire App is there a way to point Heroku where the package.json file is? Or to make it step on the right directory?
the problem originates because with the CI/CD pipeline I'm pushing the entire rootfolder Idk if I should push only my server app with the static client files, I would like to not get rid of the CI/CD pipelines if possible
CodePudding user response:
for everyone out there sill wandering the same there is a script provided by heroku where you can run logic prior to building process
In my case I've created a package.json file at rootfolder level with the following scripts
"scripts": {
"heroku-prebuild": "(cd ./backend && npm install && npm run build && cd ../frontend && npm install && npm run build:frontend)",
"start": "(cd ./backend && npm run start)",
}
with heroku-prebuild
command I could cd into mi backend protect folder then build it, then cd into my frontend protect folder, and then run my custom build:frontend
command which compiles my frontend app and then puts it inside a designated folder in my backend project to be served as static files for my backend