dougou1127 2011-12-13 18:14
浏览 33

Apache:执行.php文件等Javascript文件

Apache and PHP

PHP with Apache is really nice to play with because you can create a random test.php with

echo '<h1>Hello World</h1>';

and when you visit http://myserver.com/test.php it will show <h1>Hello World</h1>

My wish with Apache and JS

What I would like is to create a file test.js with

console.log('<h1>Hello World</h1>');

and when I visit http://myserver.com/test.js it would show <h1>Hello World</h1>

What's possible currently

The nearest attempt I found was http://www.modjs.org/ but it is no longer maintained.

Meanwhile we can run a run a NodeJS instance and simulate apache with file listing and executing javascript files based on the url, but it sucks ...

Anyone knows if it's possible? :)

Thanks!

  • 写回答

3条回答 默认 最新

  • dtslobe4694 2011-12-13 18:19
    关注

    Why would you want to do something like that. Node offers a way nicer eco-system for just demoing. For instance, grab express and make a nice simple demo:

    var app = express.createServer();
    
    app.get('/test.php', function(req, res){
        res.send('<h1>Hello World</h1>');
    });
    
    app.listen(3000);
    

    Furthermore, console.log isn't going to work for emitting code to the user. Use the methods on res to write to the user. You can call res.send multiple times.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站