docpad/docpad

DocPad should output which environment variables it used for the listening address

gtirloni opened this issue · 8 comments

Environment:

  • Fedora 25
  • node 6.9.2
  • docpad 6.79.0

Error:

templateData.site.url is defined to "http://localhost:9778" in docpad.coffee but Docpad listens on "http://myhostname:9778"

"myhostname" is not defined in /etc/hosts (tested with a fresh install).

Debug output:

$ hostnamectl 
   Static hostname: myhostname
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: 402b421233ef4b2f89f0a3eb7dac99f0
           Boot ID: 1c93bd4a413e48399080e0d3cbd9ee53
  Operating System: Fedora 25 (Twenty Five)
       CPE OS Name: cpe:/o:fedoraproject:fedora:25
            Kernel: Linux 4.8.14-300.fc25.x86_64
      Architecture: x86-64
$ ping -c 1 localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.040 ms
$ ping -c 1 -4 myhostname
PING myhostname (192.168.25.200) 56(84) bytes of data.
64 bytes from myhostname (192.168.25.200): icmp_seq=1 ttl=64 time=0.023 ms
$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

docpad -d7 run > debug.log:

$ egrep '(myhostname|localhost|url)' debug.log 
debug: Starting server on hostname myhostname port 9778
getServerUrl -> returning URL is http://myhostname:9778
getServerUrl -> returning URL is http://myhostname:9778
info: Server started on http://myhostname:9778
URL is http://localhost:9778
getServerUrl -> returning URL is http://myhostname:9778
getsimpleServerURL is http://myhostname:9778
base.url is http://localhost:9778

Workaround:

Manually add "myhostname" to /etc/hosts, adjust templateDate.site.url to "http://myhostname:9778" and restart docpad.

That is strange. I don't recall any code that tells DocPad to listen on myhostname

Same thing here. Working fine with @gtirloni workaround.

  • Fedora 25
  • Node 6.10.3
  • Docpad 6.79.4

hrmm, would someone experiencing this be able to run the following for me and let me know the results:

console.log({
    PORT: process.env.PORT,
    OPENSHIFT_NODEJS_PORT: process.env.OPENSHIFT_NODEJS_PORT,
    OPENSHIFT_IOJS_PORT: process.env.OPENSHIFT_IOJS_PORT,
    VCAP_APP_PORT: process.env.VCAP_APP_PORT,
    VMC_APP_PORT: process.env.VMC_APP_PORT,
    HOSTNAME: process.env.HOSTNAME,
    OPENSHIFT_NODEJS_IP: process.env.OPENSHIFT_NODEJS_IP,
    OPENSHIFT_IOJS_IP: process.env.OPENSHIFT_IOJS_IP,
    VCAP_APP_HOST: process.env.VCAP_APP_HOST,
    VMC_APP_HOST: process.env.VMC_APP_HOST
})

I'm sorry for the ignorance, but I have to run this in the console (inspect element) or inside a <script> tag? With both, console says that "process is not defined", so I probably didn't understand where I have to run this :P

ah okay, no worries

make a file called script.js in your home folder, put that snippet inside it, and then run it via the command line via node script.js

ooh, I see

(also, missing comma in OPENSHIFT_NODEJS_IP: process.env.OPENSHIFT_NODEJS_IP)

λ ~/Projects/ node script.js
{ PORT: undefined,
  OPENSHIFT_NODEJS_PORT: undefined,
  OPENSHIFT_IOJS_PORT: undefined,
  VCAP_APP_PORT: undefined,
  VMC_APP_PORT: undefined,
  HOSTNAME: 'myhostname',
  OPENSHIFT_NODEJS_IP: undefined,
  OPENSHIFT_IOJS_IP: undefined,
  VCAP_APP_HOST: undefined,
  VMC_APP_HOST: undefined }

Good work! There we go.

So the issue is that for some reason on your environment, the environment variable HOSTNAME is set to the value myhostname.

DocPad uses https://github.com/bevry/hostenv to grab which hostname and port it should use, and it attempts all those different environment variables.

If you want to fix this properly, you'll need to figure out where myhostname is being set. It is likely a dotfile, such as ~/.bashrc or so.

I'll make an issue over at hostenv, that it should also export which variable it went with, and that way DocPad could say what variable it used it used one. That would eliminate the guessing game that happened here. I'll rename the issue accordingly.

Let me know if you want any further help.

Closed in favour of #1081