使用节点和Jade加载外部Javascript文件时出现404错误

时间:2015-04-12 21:50:02

标签: node.js pug

我在第一次访问时使用Node来呈现页面,但是对于我的生活,我无法正确加载javascript文件。它不断出现404错误,无法找到test.js文件。 (“GET http://localhost:8080/Include/test.js”) 页面加载正确,但window.onload javascript事件不会触发。

根/ helloworld.js

var express = require('express');
var server = require('http').createServer(app);
var app = express();
app.set('views',__dirname+'/views');
app.set('view engine','jade');
app.get('/',function(req,res){
 res.render('index', { title: 'Hey', message: 'Hello!',scripts: [  '/Include/test.js']});
});
app.listen(8080);

根/包含/ test.js

window.onload = function () {
    alert('Test Passed');
}

根/视图/ index.jade

html
  <head>
  -each script in scripts
    script(type='text/javascript', src= script)
    title!= title
    </head>
  body
    h1!= message

0 个答案:

没有答案