-
Notifications
You must be signed in to change notification settings - Fork 56
Deployment
You can deploy the production build of the app to Cloud Foundry, e.g. signing up for a free account with https://run.pivotal.io/ or https://developer.swisscom.com/.
-
Install the Cloud Foundry CLI and use
cf login
to connect to your account -
Create a MongoDB service, either:
- via the marketplace in the web portal; or
- from the CLI using
cf create-service <service-name> <service-plan> cyf-mongodb
- you can usecf marketplace | grep mongo
to see what MongoDB services and plans are available, andcf service cyf-mongodb
to check when thestatus
changes tocreate succeeded
-
Add a new file,
manifest.yml
, with the following content:--- applications: - name: starter-kit-cyf buildpacks: - nodejs_buildpack disk_quota: 128M memory: 128M random-route: true services: - cyf-mongodb env: OPTIMIZE_MEMORY: true
-
Add a new file,
.cfignore
, with the following content:client/ node_modules/ server/
-
Add the following commands to the
"scripts"
object in thepackage.json
:"cloudfoundry": "npm run build && cf push",
Now you can npm run cloudfoundry
to deploy the app. You'll see something like:
name: starter-kit-cyf
requested state: started
isolation segment: iso-01
routes: <url>
last uploaded: <date>
stack: cflinuxfs3
buildpacks: nodejs
You can visit the URL in routes to see the app.
The first time you run the app, you'll need to set the environment variable for the database. Run the following commands:
-
cf env starter-kit-cyf
to see the URI for the MongoDB service (look for"uri": "mongodb://...
) -
cf set-env starter-kit-cyf MONGODB_URI <uri>
to set the environment variable -
cf restart starter-kit-cyf
to restart the app
If you have problems in the future, run cf env starter-kit-cyf
again and make sure the two values are still the same.
You can easily deploy the built front-end to Netlify, just globally install the Netlify CLI:
npm install -g netlify-cli
add the following commands into the "scripts"
object in the package.json
:
"prenetlify": "npm run cleanup && npm run build:client",
"netlify": "netlify deploy --prod --dir ./dist/static",
and add the following line to .gitignore
:
.netlify/
Now you can use npm run netlify
to rebuild the front-end and deploy it to Netlify. However note that Netlify can't host the backend, so any pages that rely on making requests to your Express server won't work.