发送html文件的Node.js不加载链接文件(css,js)

Zul*_*ler 4 extjs node.js

我正在尝试使用Node.js服务器创建az ExtJS应用程序.我的服务器代码目前看起来像这样:

var express = require('express');

var app = express();

app.get('/', function (req, res) {
    res.sendfile(filedir + '/index.html');
});

app.get('/employees', function(req, res){
console.log("hello");
});

app.listen(3000);
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中打开localhost:3000时,html文件加载,但不正确.检查firebug我看到它找不到html中的链接文件.例如

"NetworkError: 404 Not Found - http://localhost:3000/ext-4/ext-debug.js".
Run Code Online (Sandbox Code Playgroud)

这是非常合乎逻辑的,因为该URL上不存在该文件.我的问题是如何解决这个问题,所以它可以找到我的文件系统上的每个链接文件.

我显然做错了什么或遗漏了什么,我在节点上是全新的.

Dan*_*iel 5

看起来你不是在配置Express'静态文件处理程序.

尝试添加此代码:

app.configure(function() {
    app.use(express.static(path.join(__dirname, 'public')));
    app.use(express.bodyParser());
    app.use(express.logger("short"));
});
Run Code Online (Sandbox Code Playgroud)

它会去之后var app = ...是这样的:

var express = require('express');

var app = express();
app.configure(function() {
    app.use(express.static(path.join(__dirname, 'public')));
    app.use(express.bodyParser());
    app.use(express.logger("short"));
});

app.get('/', function (req, res) {
    res.sendfile(filedir + '/index.html');
});

app.get('/employees', function(req, res){
    console.log("hello");
});

app.listen(3000);
Run Code Online (Sandbox Code Playgroud)

然后将静态文件放在./public目录下.

  • `var path = require('path');` (2认同)