Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sails reverts to development connection when on heroku #2480

Closed
gkaimakas opened this issue Dec 9, 2014 · 17 comments
Closed

Sails reverts to development connection when on heroku #2480

gkaimakas opened this issue Dec 9, 2014 · 17 comments

Comments

@gkaimakas
Copy link

I have been trying to deploy my sails app on heroku using mongolab as my mongodb.

I have used the following connections, one for development and one for production:

    local_mongo : {
    adapter  : 'sails-mongo',
    host     : 'localhost',
    port     : 27017,
    database : "something"
},

  heroku_mongolab : {
     adapter   : "sails-mongo",
     url       : "mongodb://*****:******!@ds063160.mongolab.com:63160/something"
  }

I have also set my local.js file to use development environment and out that file on gitignore.

Finally on my development.js I do the following

module.exports = {
   models: {
       connection: 'local_mongo'
     }
};

on my production.js

module.exports = {

/***************************************************************************
 * Set the default database connection for models in the production        *
 * environment (see config/connections.js and config/models.js )           *
 ***************************************************************************/

models: {
   connection: 'heroku_mongolab'
}

/***************************************************************************
 * Set the port in the production environment to 80                        *
 ***************************************************************************/

//port: 80

/***************************************************************************
 * Set the log level in production environment to "silent"                 *
 ***************************************************************************/

//log: {
//   level: "silent"
//}

};

and on my package.json I changed the start script to node app.js --prod. When running locally everything works as expected, even when I run npm start, but when I deploy on heroku and look at the logs I see that it tries to connect to the localhost mongodb.

Is it a bug or am I doing something wrong?

@FerryDewe
Copy link

Yes, I am also experiencing exactly the same problems.

I tried commented out the config/env/development.js
and set the local.js (to connect to localMongo) and set the model.js (to connect to ProductionMongo).
However still have no luck, and the log on heroku still saying Error: failed to connect to [localhost:27017]

Apart from that, this Problem doesn't exist, if I set the development.js to connect other DB than Mongo connection.
So I think this is a bug regarding to the adapter: 'sails-mongo'.

@leobudima
Copy link
Contributor

I had the same problem. Worked around it by setting:

config/env/development.js:

    connections: {
        localMongo: {
            adapter: 'sails-mongo',
            host: 'localhost',
            port: 27017,
            ...
                }
    },

    models: {
        connection: 'localMongo'
    }

config/env/production.js

    connections: {
        productionMongo: {
            adapter: 'sails-mongo',
            host: 'remotehost1',
            port: 27017,
            ...
                }
    },

    models: {
        connection: 'productionMongo'
    }

auchenberg added a commit to auchenberg/app.userlove.co that referenced this issue Jan 17, 2015
@bmustata
Copy link

bmustata commented Feb 2, 2015

Same issue in here but probably it can be easily fixed in the future!

@Zhomart
Copy link

Zhomart commented Feb 9, 2015

Same issue. I used @leobudima solution.

@nwkeeley
Copy link

Same issue here and it only exists on Heroku, if I start my app locally with a NODE_ENV=production vs. NODE_ENV=development everything works fine... the NODE_ENV i set in my ProcFile and also via heroku tool belt no luck.

I want to do the "right" thing and use connections.js but I think I am going to have to do what @leobudima has done.

@Ignigena
Copy link
Contributor

Ignigena commented Mar 1, 2015

For what it's worth, I didn't encounter this issue until I upgraded my dyno to the cedar-14 stack. My project had until now been running on cedar (which is deprecated) using Sails v10.5, but immediately upon upgrading I experienced the same issue with my development connection being used rather than production.

The solution provided by @leobudima served as a good temporary fix.

@dottodot
Copy link

dottodot commented Mar 5, 2015

I'm having the same issue but none of the suggestion above seem to work, so don't know what I'm missing.

@lommaj
Copy link

lommaj commented Mar 15, 2015

Im having the same issue, setting environment variables doesnt seem to do anything. I also tried the solution @leobudima mentioned and thats not working. Still looks to localhost for me no matter what.

@lommaj
Copy link

lommaj commented Mar 15, 2015

I've confirmed that no matter what, it always defaults to whatever connection you have in /config/env/development.

@agustin3a
Copy link

I finally found the solution, in the package json from the sails app you have to change the start script.

"scripts": {
    "start": "node app.js --NODE_ENV",
    "debug": "node debug app.js"
  },

and add the NODE_ENV variable to heroku.

heroku config:set NODE_ENV=prod

@prescottprue
Copy link

Both @leobudima and @agustin3a solutions did not work for me. What causes the default to local?

Apparently having multiple connections with the same adapter can cause the problem: http://stackoverflow.com/questions/22775028/sails-fails-to-load-when-using-remote-mongo-db

@bmatto
Copy link

bmatto commented Aug 19, 2015

I was seeing this issue - and removing other 'sails-mongo' configurations from config/connections.js seemed to fix it for me. There are other SO posts that contend one could put those directly in the config/env/* files as a potential fix as well. I assume in those fixes one would also remove any reference to the adapter in use from config/connections.js.

@sailsbot
Copy link

Thanks for posting, @gkaimakas. I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

  • review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
  • create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.

Thanks so much for your help!

@FelipeMiranda
Copy link

I'm having the exact same problem on Bluemix

@FelipeMiranda
Copy link

FelipeMiranda commented Oct 28, 2016

2016-10-28T02:55:01.63-0200 [App/0]      ERR 
2016-10-28T02:55:01.63-0200 [App/0]      ERR /home/vcap/app/node_modules/mongodb/lib/server.js:236
2016-10-28T02:55:01.63-0200 [App/0]      ERR         process.nextTick(function() { throw err; })
2016-10-28T02:55:01.63-0200 [App/0]      ERR                                       ^
2016-10-28T02:55:01.64-0200 [App/0]      ERR Error: connect ECONNREFUSED 127.0.0.1:27017
2016-10-28T02:55:01.64-0200 [App/0]      ERR     at Object.exports._errnoException (util.js:907:11)
2016-10-28T02:55:01.64-0200 [App/0]      ERR     at exports._exceptionWithHostPort (util.js:930:20)
2016-10-28T02:55:01.64-0200 [App/0]      ERR     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)
2016-10-28T02:55:01.83-0200 [App/0]      ERR npm ERR! Linux 3.19.0-33-generic
2016-10-28T02:55:01.83-0200 [App/0]      ERR npm ERR! argv "/home/vcap/app/vendor/node/bin/node" "/home/vcap/app/vendor/node/bin/npm" "start"
2016-10-28T02:55:01.84-0200 [App/0]      ERR npm ERR! node v4.6.0
2016-10-28T02:55:01.84-0200 [App/0]      ERR npm ERR! npm  v2.15.9
2016-10-28T02:55:01.84-0200 [App/0]      ERR npm ERR! code ELIFECYCLE
2016-10-28T02:55:01.85-0200 [App/0]      ERR npm ERR! Exit status 1
2016-10-28T02:55:01.85-0200 [App/0]      ERR npm ERR! 
2016-10-28T02:55:01.85-0200 [App/0]      ERR npm ERR! Failed at the elinke-aovivo-server@0.0.0 start script 'node app.js --prod'.
2016-10-28T02:55:01.85-0200 [App/0]      ERR npm ERR! This is most likely a problem with the elinke-aovivo-server package,
2016-10-28T02:55:01.85-0200 [App/0]      ERR npm ERR! not with npm itself.
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR!     node app.js --prod
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR!     npm bugs elinke-aovivo-server
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR! Or if that isn't available, you can get their info via:
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR! 
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR!     npm owner ls elinke-aovivo-server
2016-10-28T02:55:01.86-0200 [App/0]      ERR npm ERR! There is likely additional logging output above.
2016-10-28T02:55:01.89-0200 [App/0]      ERR npm ERR! Please include the following file with any support request:
2016-10-28T02:55:01.89-0200 [App/0]      ERR npm ERR!     /home/vcap/app/npm-debug.log

@astw
Copy link

astw commented Nov 19, 2016

I am using sails 0.12.10, and sails-mongo 0.12.5, I still can not connect to remote mongo db. And I also tried all possible solutions suggested by people.

@rvicenzo
Copy link

I had the same problem, so combined the @leobudima and @agustin3a solutions and works fine for me.
PS: Let just one connection configured in config/connections.js

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

No branches or pull requests