我正在尝试执行本教程:http://angular.github.io/angular-phonecat/step-11/app/#/phones 。当我将这些文件放入 MAMP 中时,它就可以工作了。但是,当我尝试创建 Node 服务器时,它不会发送 js 文件。我使用 InspectElement 进行了检查。它只发送index.html。为什么会发生这种情况?
//server.js
var express = require('express');
var app = express();
var port = process.env.PORT || 8887;
app.configure(function()
{
app.use(express.static(__dirname + './public'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
});
require('./app/router')(app);
app.listen(port);
console.log('Listening to port 8887');
exports = module.exports = app;
//./app/router.js
module.exports = function(app){
app.get('/', function(req, res){
res.sendfile('./public/index.html');
});
最佳答案
将 ./public
更改为 /public/
并确保您的脚本位于 public 文件夹中。
关于javascript - Node 不发送脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24312534/