Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Deployment

Jonathan Sharpe edited this page Jul 14, 2019 · 2 revisions

Heroku

See instructions in README.

Cloud Foundry

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 use cf marketplace | grep mongo to see what MongoDB services and plans are available, and cf service cyf-mongodb to check when the status changes to create 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 the package.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.

DB Setup

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.

Netlify

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.

Clone this wiki locally