Skip to content

Instantly share code, notes, and snippets.

@leosuncin
Forked from facultymatt/Procfile
Last active August 29, 2015 14:20
Show Gist options
  • Save leosuncin/8b8aebd8d06badbea78b to your computer and use it in GitHub Desktop.
Save leosuncin/8b8aebd8d06badbea78b to your computer and use it in GitHub Desktop.
Deployd on Heroku
{
"name": "app_name",
"version": "0.0.1",
"description": "Super awesome app",
"keywords": [],
"homepage": "*.heroku.com",
"author": "You!",
"contributors": [],
"dependencies": {
"deployd": ">= 0"
},
"scripts": {
"start": "node server"
},
"engines": {
"node": "~0.10.0",
"npm": "~1.4.0"
},
"license": "MIT"
}
web: node server
// require deployd
var deployd = require('deployd');
var url = require('url');
(function() {
'use strict';
var dbUrl = url.parse(process.env.MONGOLAB_URI ||
'mongodb://:@localhost:27017/my_database');
var port = process.env.PORT || 3000;
// configure database etc.
var server = deployd({
port: port,
env: 'production',
db: {
host: dbUrl.hostname,
port: parseInt(dbUrl.port),
name: dbUrl.pathname.slice(1),
credentials: {
username: dbUrl.auth.split(':')[0],
password: dbUrl.auth.split(':')[1]
}
}
});
// heroku requires these settings for sockets to work
if (server.sockets.manager) {
server.sockets.manager.settings.transports = ['xhr-polling'];
}
// start the server
server.listen();
// debug
server.on('listening', function() {
console.log('Server is listening on port: ' + port);
});
// Deployd requires this
server.on('error', function(err) {
console.error(err);
process.nextTick(function() { // Give the server a chance to return an error
process.exit();
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment