Created
March 21, 2019 15:53
-
-
Save velizarn/7980d2349c0c4eedfc0bfb32b32d5048 to your computer and use it in GitHub Desktop.
Nodejs postbuild script for Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
require('dotenv').config(); | |
const { | |
HEROKU_APP_NAME, | |
AUTH_TOKEN | |
} = process.env; | |
const | |
request = require('request-promise'), | |
logger = require('heroku-logger'); | |
const resouceUrl = `https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars`; | |
const options = { | |
method: 'PATCH', | |
uri: resouceUrl, | |
body: { | |
LAST_POSTBUILD_EXECUTION: (new Date()).toISOString() | |
}, | |
headers: { | |
'Content-Type': 'application/json', | |
'Accept': 'application/vnd.heroku+json; version=3', | |
'Authorization': `Bearer ${AUTH_TOKEN}` | |
}, | |
json: true | |
}; | |
request(options) | |
.then((response) => { | |
delete response.AUTH_TOKEN; | |
logger.info(JSON.stringify(response, null, 2)); | |
}) | |
.catch((err) => { | |
logger.error(err + ''); | |
}); | |
/* | |
1) update your package.json file: | |
"scripts": { | |
"heroku-postbuild": "node path-to-postbuild.js", | |
} | |
2) enable dyno metadata for your Heroku app | |
heroku labs:enable runtime-dyno-metadata -a <app_name> | |
3) create new long-lived user authorization token and save it to an app config var, e.g. AUTH_TOKEN | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment