Skip to content

Instantly share code, notes, and snippets.

@facultymatt
Created April 12, 2013 16:23
Show Gist options
  • Save facultymatt/5373247 to your computer and use it in GitHub Desktop.
Save facultymatt/5373247 to your computer and use it in GitHub Desktop.
Get Deployd running on Heroku!
{
"name": "app_name",
"version": "0.0.1",
"description": "Super awesome app",
"keywords": [],
"homepage": "",
"author": "You!",
"contributors": [],
"dependencies": {
"deployd": ">= 0"
},
"scripts": {
"start": "node server"
},
"engines": {
"node": "0.8.x",
"npm": "1.2.x"
},
"license": "MIT"
}
web: node server
// require deployd
var deployd = require('deployd');
// configure database etc.
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'something.mongolab.com',
port: 27857,
name: 'database_name',
credentials: {
username: 'username',
password: 'password'
}
}
});
// heroku requires these settings for sockets to work
server.sockets.manager.settings.transports = ["xhr-polling"];
// start the server
server.listen();
// debug
server.on('listening', function() {
console.log("Server is listening on port: " + process.env.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();
});
});
@santibecerra
Copy link

Great work. I don't knew where to "configure" the io object. Thanks for sharing

@abulte
Copy link

abulte commented Jun 18, 2013

Very useful, thanks!

@apgiorgi
Copy link

Thank you!

@robotnic
Copy link

robotnic commented May 1, 2014

Thanks for the script!

For websockets on heroku it is possible to enable websockets (beta)
heroku labs:enable websockets

@robotnic
Copy link

robotnic commented May 1, 2014

I have problems with memory leaks. Every get request takes up to 15 MByte and never frees the memory.
To see the memory usage I enabled this option on heroku:

heroku labs:enable log-runtime-metrics

and then

heroku logs --tail

@angelxmoreno
Copy link

When i try this i get
remote: ! Push rejected, no Cedar-supported app detected
! [remote rejected] master -> master (pre-receive hook declined)

Anyone else get this?

@mattiaaccornero
Copy link

@robotnic did you solve your memory leaks issue? In affirmative case, how?

Thanks

@vpxavier
Copy link

FYI, I had trouble having this working. I solved my issues using

 "engines": {
    "node": "0.10.x",
    "npm":  "2.2.x"
  }

And I also had to create a "resources" folder in the root of my heroku app folder.
Note that the resources folder, has it is empty might be ignored by git, so I added an empty file into it.

I hope it help someone has I lost a couple of hours solving this.

@NicolasRitouet
Copy link

I created a demo to use Deployd on Heroku with the deploy button:
https://github.com/NicolasRitouet/deployd-heroku-demo
It doesn't work with the key yet.
The resources folder is not needed anymore, if Deployd doesn't find it, it will create it.
I haven't tested everything, but the basic features seems to work.

@vpxavier
Copy link

vpxavier commented Mar 4, 2015

@RishabhTayal
Copy link

Not able to run the server. How can I access my apis and dashboard?

@tdreid
Copy link

tdreid commented Feb 27, 2016

If I understand this correctly the following may not work in socket.io 1.0 and later...

` server.sockets.manager.settings.transports = ["xhr-polling"];`

In any case that line throws an error for me: Cannot read property 'settings' of undefined.

The socket.io docs say to do this...

var socket = require('socket.io')({
  // options go here
});

But I'm not clear how to apply that approach in a script like the one above.

Any advice is very much appreciated.


UPDATE:
Got it working by replacing line 20 with...

server.sockets.server.set('transports', ["xhr-polling"]);

These were also suggested in a stackoverflow answer, but I haven't tried them yet...

var server = deployd({
    socketIo: {
        options: { transports : ['xhr-polling'] }
    }
});

or

server.sockets.server.eio.transports = ['xhr-polling'];

@p0six
Copy link

p0six commented Apr 23, 2018

got this working just now (4/22/18) using the following server.js:

var deployd = require('deployd');

// configure database etc.
var server = deployd({
  port: process.env.PORT || 5000,
  env: 'production',
  db: {
    connectionString: "mongodb://<username>:<password>@<hostname>:<password>/<db name>"
  }
});

server.sockets.server.set('transports', ['xhr-polling']);

// start the server
server.listen();

// debug
server.on('listening', function() {
  console.log("Server is listening on port: " + process.env.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();
  });
});```

@p0six
Copy link

p0six commented Apr 23, 2018

Also seemed to work without using the "server.sockets.server.set" line - unsure if that's truly needed or not, but kept it in anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment