deda-ca / cgi-node

CGI Node.js complete module to replace PHP on shared hosting such as GoDaddy
http://www.cgi-node.org/
MIT License
172 stars 21 forks source link

EXCEPTION: Arguments to path.resolve must be strings #7

Open jeancf opened 9 years ago

jeancf commented 9 years ago

I am trying to install cgi-node on a Raspberry Pi (ARM6) running Arch Linux, Lighttpd 1.4.35 and nodejs 0.10.35.

I transposed the installation procedure described in the GoDaddy tutorial as best as I could. However when I try to load a page containing <? cgiNodeInfo() ?> I get the following error in red on the page:

EXCEPTION: Arguments to path.resolve must be strings

TypeError: Arguments to path.resolve must be strings
at Object.exports.resolve (path.js:313:15)
at CgiHttpContext.mapPath (/srv/http/cgi-bin/cgi-node.js:139:15)
at CgiHttpContext.include (/srv/http/cgi-bin/cgi-node.js:152:19)
at onReady (/srv/http/cgi-bin/cgi-node.js:954:43)
at Object. (/srv/http/cgi-bin/cgi-node.js:960:46)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Which I think is a nodejs error message.

My lighttpd.conf:

server.port         = 80
server.username     = "http"
server.groupname    = "http"

# For cgi-node
server.modules += ( "mod_cgi" )

server.document-root    = "/srv/http"
server.errorlog         = "/var/log/lighttpd/error.log"
server.breakagelog      = "/var/log/lighttpd/breakage.log"
dir-listing.activate    = "enable"
index-file.names        = ( "index.html" )
mimetype.assign         = (
    ".html" => "text/html",
    ".txt"  => "text/plain",
    ".css"  => "text/css",
    ".js"   => "application/x-javascript",
    ".jpg"  => "image/jpeg",
    ".jpeg" => "image/jpeg",
    ".gif"  => "image/gif",
    ".png"  => "image/png",
    ""      => "application/octet-stream"
    )

    cgi.assign = (
        ".py"  => "/usr/bin/python",
        ".js"  => "/usr/bin/node",
        ".jss" => "/srv/http/cgi-bin/cgi-node.js" )

Thanks for your help.

deda-ca commented 9 years ago

CGI-Node expecting "process.env.PATH_TRANSLATED" to be the full path of the javascript file to be executed. "PATH_TRANSLATED" is added to the environment variable when Apache executes Node.js as a CGI. I think lighttpd uses a different environment variable name (not sure but it could be PATH_INFO).

Try printing out the lighttpd environment variables and see which one points to the javascript file and update cgi-node.js accordingly (/srv/http/cgi-bin/cgi-node.js: Line number: 960, column: 46).

Let me know if this works. If not, I can setup a similar environment on my Raspberry PI and debug it.

Hope this helps.

jeancf commented 9 years ago

Great feedback, thanks!

Actually I found on this PHP manual page the following note:

As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly under the Apache 2 SAPI in contrast to the situation in Apache 1, where it's set to the same value as the SCRIPT_FILENAME server variable when it's not populated by Apache. This change was made to comply with the CGI specification that PATH_TRANSLATED should only exist if PATH_INFO is defined. Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.

When I replaced process.env.PATH_TRANSLATED by process.env.SCRIPT_FILENAME in cgi-node.js as you indicated I was able to get the cgiNodeInfo() content properly.

Cheers,

/~JC

tedbeer commented 8 years ago

Confirmed. I use NAS4Free based on FreeBSD 9 with built-in lighttpd. To make it run:

   cgi.assign += ( ".jscript"  => "/path/to/script/cgi-node.js")