From 41f8589b6434b96c846ff67ceb212c70ff4ba46c Mon Sep 17 00:00:00 2001 From: midudev Date: Sun, 8 Aug 2021 21:24:40 +0200 Subject: [PATCH] Add healthcheck and do rollback if not working --- .github/workflows/pipeline.yml | 2 ++ app.js | 9 +++++++++ package.json | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index f3e4b40..4771f8a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -35,3 +35,5 @@ jobs: heroku_api_key: ${{secrets.HEROKU_API_KEY}} heroku_app_name: ${{secrets.HEROKU_APP}} heroku_email: ${{secrets.HEROKU_API_EMAIL}} + healthcheck: "https://${{secrets.HEROKU_APP}}/health" + rollbackonhealthcheckfailed: true diff --git a/app.js b/app.js index ba924d9..bcdac8f 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,18 @@ const express = require('express') const app = express() +const { version } = require('./package.json') // Heroku dynamically sets a port const PORT = process.env.PORT || 5000 +app.get('/health', (req, res) => { + res.send('ok') +}) + +app.get('/version', (req, res) => { + res.send(version) +}) + app.use(express.static('dist')) app.listen(PORT, () => { diff --git a/package.json b/package.json index 98d3366..145e5b8 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "Full Stack Open", "main": "src/index.js", "scripts": { - "start": "webpack-dev-server --open --mode development", + "dev": "webpack-dev-server --open --mode development", "start-test": "NODE_ENV=test node app.js", - "start-prod": "node app.js", + "start": "node app.js", "test": "jest", "eslint": "eslint './**/*.{js,jsx}'", "build": "webpack --mode production",