Skip to content

Instantly share code, notes, and snippets.

@superjojo140
Last active April 24, 2020 12:35
Show Gist options
  • Save superjojo140/201009436fc6f45c32129ba9ea82ea00 to your computer and use it in GitHub Desktop.
Save superjojo140/201009436fc6f45c32129ba9ea82ea00 to your computer and use it in GitHub Desktop.
Microservices workflow

Microservices - Deployment on heroku

Setup

Enviroment Variables

Use enviroment variables for ports and urls!

Set environment variables for Angular projects in environment.prod.ts and use with environment.warehouseURL

Set environment variables for node projects on heroku (https://heroku.com -> Project Overview -> Settings -> Reveal Config Vars) and use with process.env.shopBackendUrl

For each project:

  • Create new git repo for every single application: git init
  • Make sure there's a .gitignore
  • Copy neccessary dependencies (typescript, ...) from devDependencies to dependencies (in package.json)
  • use ports given by heroku (e.g. in app.ts): const port = Number(process.env.PORT || oldPortForLocalTesting)
  • use urls from heroku instad of localhost... (use env variables)
    • e.g. shopURL: = process.env.shopBackendUrl || 'http://localhost:5001/warehouse2shop'
  • Commit all changes to git
  • run heroku create APP_NAME
  • push changes to git: git push heroku master

Find errors or console outputs with: heroku logs

[Backend Only] Set database

  • on heroku page for the current project click on Configure Add-ons
  • search for Heroku Postgres
  • Select Hobby Dev - Free
  • The DATABASE_URL is automatically configured as env variable
  • in ormconfig.ts add: url : process.env.DATABASE_URL || 'postgres://user:password@localhost:port/dbName'
  • remove host, port, username, password, database properties

[Frontend Only] Serve angular files

  • ng serve does not work! Angular project needs to be compiled and then served from a simple static node webserver
  • Change npm Scripts (in package.json)
    • build: "ng build --prod"
    • start: "node server.js"
  • Create server.js file in project root for serving local files
  • Install express: npm install express
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment