39
loading...
This website collects cookies to deliver better user experience
nxDeployHeroku_entryPoint
.git clone [email protected]:<your_username>/nx-photos.git
# Or using Https
git clone https://github.com/<your_username>/nx-photos.git
cd nx-photos
git checkout nxDeployHeroku_entryPoint
heroku login
ktrz-
prefix for the app names. Please replace it with your own prefix so that the application names don't collide with each other.heroku create -a ktrz-nx-photos-api
heroku buildpacks:add
command can be used:heroku buildpacks:add -a ktrz-nx-photos-api heroku/nodejs
Procfile
file to specify the commands that are executed on application startup. The default configuration allows for only one Procfile and it has to be in the repository root. For it to work with the monorepo with multiple applications, we need a way to configure multiple Procfiles in the repository. For this purpose, a multi-procfile
buildpack can be used. We can add it using a similar command to the previous one:heroku buildpacks:add -a ktrz-nx-photos-api heroku-community/multi-procfile
web: node dist/apps/photo/api/main.js
apps/photo/api/Procfile
PROCFILE
env variable for the Heroku application. We can do it using the following command:heroku config:set -a ktrz-nx-photos-api PROCFILE=apps/photo/api/Procfile
build
script from the package.json
file to build the application. We need a more customizable way of building an application so we can configure which application in a monorepo to build. By defining a heroku-postbuild
script, we tell Heroku to not use a default build
one and use our custom script instead. Let's create the following script:scripts: {
"heroku-postbuild": "nx build $PROJECT_NAME --prod"
}
package.json
PROJECT_NAME
env variable is used to determine which application to build. It needs to be configured on the Heroku environment:heroku config:set -a ktrz-nx-photos-api PROJECT_NAME=photo-api
git checkout -b nx-photo-deploy
git push -u origin photo-api-deploy
Deploy
tab, choose the GitHub method, search for your repository, and click Connect
:scripts: {
"heroku-postbuild": "nx build $PROJECT_NAME --prod"
}
package.json
heroku create -a ktrz-nx-photos-api
heroku config:set -a ktrz-nx-photos-api PROJECT_NAME=photo-api
heroku buildpacks:add -a ktrz-nx-photos-api heroku/nodejs
heroku buildpacks:add -a ktrz-nx-photos-api heroku-community/multi-procfile
# create `apps/photo/api/Procfile` file
heroku config:set -a ktrz-nx-photos-api PROCFILE=apps/photo/api/Procfile
# create another Heroku app
heroku create -a ktrz-nx-photos-fe
# add same buildpacks
heroku buildpacks:add -a ktrz-nx-photos-fe heroku/nodejs
heroku buildpacks:add -a ktrz-nx-photos-fe heroku-community/multi-procfile
# configure Procfile
heroku config:set -a ktrz-nx-photos-fe PROCFILE=apps/photo/fe/Procfile
# set PROJECT_NAME env variable
heroku config:set -a ktrz-nx-photos-fe PROJECT_NAME=photo-fe
index.html
and let Angular handle the rest. We can use another buildpack to accomplish that.heroku buildpacks:add -a ktrz-nx-photos-fe heroku-community/static
static.json
file. We can do a basic configuration like so:{
"root": "dist/apps/photo/fe/",
"routes": {
"/**/*.html": "index.html"
}
}
static.json
/api
proxy for the backend. This also can be configured within static.json file:{
"proxies": {
"/api/": {
"origin": "https://ktrz-nx-photos-api.herokuapp.com/api/"
}
}
}
static.json
web: bin/boot
apps/photo/fe/Procfile
Deploy
tab, choose GitHub method, search for your repository, and click Connect
.