Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor: How to get the hostname, server side

Tags:

node.js

meteor

On the client I can use window.location.hostname to get the hostname. How can I get the same on the server? I need this to work behind an Apache proxy, unfortunately Meteor.absoluteUrl() gives me localhost:3000. I also want it to work for different domains, I want one Meteor app that gives different results for different domains.

This question is somewhat related: Get hostname of current request in node.js Express

like image 831
kqw Avatar asked Jun 18 '14 15:06

kqw


3 Answers

Meteor.absoluteUrl() given that your ROOT_URL env variable is set correctly.

See the following docs: http://docs.meteor.com/#meteor_absoluteurl.

Meteor doesn't know the outside-facing address of the proxy that it's sitting behind, and the (virtual) domain that this proxy was accessed by would have to be forwarded to the Meteor app for it to do what you are asking for. I don't think this is currently supported.

like image 104
imslavko Avatar answered Nov 15 '22 21:11

imslavko


According to this you can now get the Host header inside Meteor.publish() and Meteor.methods() calls by accessing:

this.connection.httpHeaders.host

Elsewhere in the application, it's probably difficult to determine the Host header that is being used to connect.

like image 38
chmac Avatar answered Nov 15 '22 21:11

chmac


If you want the hostname of the server, as configured in /etc/hostname for example:

With meteorite:

$ mrt add npm

In your server code:

os = Npm.require('os')
hostname = os.hostname()

This has no connection to the Host header provided in the incoming request.

updated answer with some of chmac's words from the comment below

like image 37
kqw Avatar answered Nov 15 '22 20:11

kqw