【发布时间】:2016-10-25 18:53:34
【问题描述】:
按照here 的建议,我可以在 JavaScript 中获得一个 shell 脚本,它在 node.js 下运行并打印一些 hello world html:
test.cgi
-------
#!/usr/local/bin/node
console.log("Content-Type: text/html; charset=utf-8\n");
console.log("<html><body><h1>hello node.js world</h1></body></html>");
-------
并运行它:
$ ./test.cgi
Content-Type: text/html; charset=utf-8
<html><body><h1>hello node.js world</h1></body></html>
它在 Apache 中也能按预期工作,并在浏览器中显示预期的 HTML。
现在转到 CoffeeScript(注意这里可爱的三引号文档,Python 风格):
ctest.cgi
-------
#!/usr/bin/env coffee
console.log("Content-Type: text/html; charset=utf-8\n");
console.log('''<html><body><h1>hello CoffeeScript world
</h1></body></html>''');
-------
这在本地运行时有效:
$ ./ctest.cgi
Content-Type: text/html; charset=utf-8
<html><body><h1>hello CoffeeScript world
</h1></body></html>
但不是在 Apache 中:
Internal Server Error
为什么这不起作用?
【问题讨论】:
标签: apache node.js cgi coffeescript env