Skip to content

Instantly share code, notes, and snippets.

@velizarn
Created March 21, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velizarn/7980d2349c0c4eedfc0bfb32b32d5048 to your computer and use it in GitHub Desktop.
Save velizarn/7980d2349c0c4eedfc0bfb32b32d5048 to your computer and use it in GitHub Desktop.
Nodejs postbuild script for Heroku
'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