使用Node的http模块[duplicate]为angular.min.js提供服务

问题描述 投票:1回答:1

这个问题在这里已有答案:

是否可以通过仅使用来自节点的http模块来提供angular.js,而无需任何其他框架?我是否拥有简单Web应用程序所需的所有功能?

这就是我尝试过的:

http.createServer(function(req, res){
    fs.readFile('./src/index.html', function(err, f1){
        res.writeHead(200, {'Content-Type': 'text/html'})
        res.write(f1)
        fs.readFile('./src/angular.min.js', function(err, f2){
            res.writeHead(200, {'Content-Type': 'application/javascript'})
            res.write(f2)
            res.end()
        })
    })
}).listen(6666)
My intent was to load javascript file that my html document depend on. Even though I'm able to see in DevTools under network tab that GET was made succesfuly to these files, they don't seem to interact as if I would run index.html from file explorer. If angular.min.js was successfully loaded scope variables wouldn't look like "{{ data }}", they would have real value without braces.

是否有一些我错过的步骤,或者我需要阅读的有关如何理解文件链接的内容?

javascript node.js angularjs http google-chrome-devtools
1个回答
0
投票

你只需要一个静态服务器。它没有角度的任何东西。

你可以使用像http-server这样的简单包,或者像this answer一样自己编写代码

© www.soinside.com 2019 - 2024. All rights reserved.