Created
April 12, 2013 16:23
-
-
Save facultymatt/5373247 to your computer and use it in GitHub Desktop.
Get Deployd running on 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
{ | |
"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" | |
} |
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
web: node server |
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
// 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(); | |
}); | |
}); |
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();
});
});```
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
If I understand this correctly the following may not work in socket.io 1.0 and later...
In any case that line throws an error for me: Cannot read property 'settings' of undefined.
The socket.io docs say to do this...
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...
or
server.sockets.server.eio.transports = ['xhr-polling'];