Skip to content

How to change 'localhost' so app can be accessed from outside/public IP? #107

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

Closed
randwa1k opened this issue Mar 2, 2014 · 11 comments
Closed

Comments

@randwa1k
Copy link

randwa1k commented Mar 2, 2014

I have installed generator-angular-fullstack on my AWS EC2 machine with a public IP address without any major problems (just the jpegtran minor issue). When I run grunt serve, it starts "Waiting ... " as expected, but none of my browsers could connect to the.public.ip:9000.

I've seen this before with just the plain generator-angular. It was solved in Gruntfile.js by changing localhost to "0.0.0.0 to access the server from outside".

I did try replacing all the "localhost"s to "0.0.0.0" in my current angular-fullstack's Gruntfile.js, but I still can't connect to it, nothing seems to change from the grunt serve output at least.

If the localhost is indeed the problem, how should I fix it?
If not, what is causing the failure to connect on browsers?

Here is my grunt serve output:

Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module 'jpegtran-bin'

Running "serve" task

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "bower-install:app" (bower-install) task

Running "concurrent:server" (concurrent) task

    Loading "imagemin.js" tasks...ERROR
    >> Error: Cannot find module 'jpegtran-bin'

    Running "copy:styles" (copy) task
    Copied 1 files

    Done, without errors.


    Execution Time (2014-03-02 00:36:37 UTC)
    loading tasks   6ms  ▇▇▇▇▇▇▇▇▇▇▇ 21%
    copy:styles    21ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 75%
    Total 28ms

Running "autoprefixer:dist" (autoprefixer) task
Prefixed file ".tmp/styles/main.css" created.

Running "express:dev" (express) task
Starting background Express server
debugger listening on port 5858
Express server listening on port 9000 in development mode

Running "open:server" (open) task

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (/home/ubuntu/fs_a/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:536:74)
    at EventEmitter.emit (events.js:106:17)
    at null.<anonymous> (/home/ubuntu/fs_a/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (/home/ubuntu/fs_a/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:415:13)

Running "watch" task
Waiting...
Reloading watch config...
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module 'jpegtran-bin'

Running "watch" task
Waiting...OK
>> File "Gruntfile.js" changed.

Completed in 0.001s at Sun Mar 02 2014 00:37:16 GMT+0000 (UTC) - Waiting...

Reloading watch config...
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module 'jpegtran-bin'

Running "watch" task
Waiting...
@DaftMonk
Copy link
Member

DaftMonk commented Mar 2, 2014

I see you're getting errors with jpegtran and mongoose, maybe this would help? #106 (comment)

@randwa1k
Copy link
Author

randwa1k commented Mar 2, 2014

Thanks so much for the fast response. I followed everything you suggested on a new directory except I ran bower install first and then npm install. The jpegtran errors went away, but I still have a database error and I still cannot connect on a browser.

I am brand new to this, so I don't know the background of running these apps, but shouldn't I start the Mongo server before running grunt serve? Is that possibly why there is a problem?

$ grunt serve
Running "serve" task

Running "clean:server" (clean) task

Running "bower-install:app" (bower-install) task

Running "concurrent:server" (concurrent) task

    Running "copy:styles" (copy) task
    Copied 1 files

    Done, without errors.


    Execution Time (2014-03-02 02:31:09 UTC)
    loading tasks   6ms  ▇▇▇▇▇▇▇▇▇▇▇▇ 24%
    copy:styles    18ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 72%
    Total 25ms

Running "autoprefixer:dist" (autoprefixer) task
Prefixed file ".tmp/styles/main.css" created.

Running "express:dev" (express) task
Starting background Express server
debugger listening on port 5858
Express server listening on port 9000 in development mode

Running "open:server" (open) task

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (/home/ubuntu/fs_b/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
    at EventEmitter.emit (events.js:106:17)
    at null.<anonymous> (/home/ubuntu/fs_b/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (/home/ubuntu/fs_b/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:415:13)

Running "watch" task
Waiting...

@DaftMonk
Copy link
Member

DaftMonk commented Mar 2, 2014

Yep, that's right. That should fix your connection error.

@randwa1k
Copy link
Author

randwa1k commented Mar 2, 2014

How should I start Mongo?

I tried:

$ mongo
The program 'mongo' is currently not installed.  You can install it by typing:
sudo apt-get install mongodb-clients

and

$ mongodb
No command 'mongodb' found, did you mean:
 Command 'mongod' from package 'mongodb-server' (universe) 
mongodb: command not found

Shouldn't I already have Mongodb/mongoose installed in my project's node_module? How should I use them?

/node_modules$ ls *mongo*

connect-mongo:
index.js  lib  node_modules  package.json  readme.md

mongoose:
contributing.md  examples    index.js  node_modules  readme.md         static.js
contrun.sh       history.md  lib       package.json  release-items.md  website.js

mongoose-unique-validator:
index.js  package.json  readme.md  spec

(btw, I have "generator-angular-fullstack" installed in my ~/local/lib/node_modules.)

Do I need some global Mongo/Mongoose installed in a root directory?

@DaftMonk
Copy link
Member

DaftMonk commented Mar 2, 2014

Well mongoose was installed through npm, so that should be fine, but it relies on a connection to a mongoDB database. MongoDB has to be installed separately from the project, it needs to be installed on the system like Node does.

I'm not sure how it works with amazon web service, but for running it on a local computer I just install it from http://www.mongodb.org/downloads.

If the node server is launched in production mode, the mongo URI looks like this:

// lib/config/env/production.js
uri: process.env.MONGOLAB_URI ||
     process.env.MONGOHQ_URL ||
     'mongodb://localhost/fullstack'

It will look for environment URIs for mongolab or mongohq, and if it doesn't find either one it will default to the local mongodb installation, and create or use the fullstack DB.

So it might be easier for you to use mongolab/mongohq or some other third party mongodb hosting rather than setting it up mongoDB on AWS, but I don't know how AWS works.

@randwa1k
Copy link
Author

randwa1k commented Mar 2, 2014

So if I understand your reply correctly, angular-fullstack does not include Mongodb. I have to get it on my own (it's basically an Ubuntu machine provided by AWS, so being AWS is nothing special). Angular-fullstack only includes the package to connect to Mongodb, i.e. connect-mongo?

btw, thanks for the quick responses.

@DaftMonk
Copy link
Member

DaftMonk commented Mar 2, 2014

Exactly.

@randwa1k
Copy link
Author

randwa1k commented Mar 2, 2014

Thanks! Where exactly in angular-fullstack project do I configure the settings for MongoDB?

(I'll leave this issue open until I can get it from the browser, in case the "localhost" does become an issue.)

@DaftMonk
Copy link
Member

DaftMonk commented Mar 2, 2014

No problem :). The configurations are in the lib/config/env folder, the environment config is loaded depending on what environment node is running in. And the actual connection is initialized in server.js

DaftMonk added a commit that referenced this issue Mar 2, 2014
@DaftMonk DaftMonk closed this as completed Mar 2, 2014
@randwa1k
Copy link
Author

randwa1k commented Mar 3, 2014

Hi DaftMonk, so it turns out you were right all along, "localhost" wasn't the issue. :D

Once I got MongoDB installed and started on my machine (I want the db to be local for now), the app automatically connected. Everything works.

You rock! Thank you!

@Globik
Copy link

Globik commented Jun 26, 2015

But why mongos.js can't connect to localhost: 27017 without internet connection? I am on windows7. Mongodb shell works just fine, also port 28017 is ok. But in browser there is error 500.

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

No branches or pull requests

3 participants