简体   繁体   中英

Problems using express.static in node.js

I will start by saying that I am new to node.js and can not figure what I messed up. I am attempting to follow an tutorial to build a basic skeleton structure that I can use for over and over again. I believe my problem is comes from my use of the express.static not serving up my files correctly. Basically I have server.js file with the following code:

app.configure(function() {
    app.set('views', __dirname + '/server/views');
    app.set('view engine', 'jade');
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(stylus.middleware(
        {
            src: __dirname + '/public',
            compile: compile
        }
    ));
    app.use(express.static(__dirname + '/public'));
});

app.get('/partials/:partialPath', function(req, res) {
    res.render('partials/' + req.params.partialPath);
})

I also have another file named scripts.jade with the following code:

script(type="text/javascript", src="/vendor/jquery/jquery.js")
script(type="text/javascript", src="/vendor/angular/angular.js")
script(type="text/javascript", src="/vendor/angular-resource/angular-resourse.js")
script(type="text/javascript", src="/vendor/angular-route/angular-route.js")
script(type="text/javascript", src="/app/app.js")

When I navigate to the web site (http://localhost:3030/) I get the following text in my console and get a blank page in the browser:

在此处输入图片说明 I have seen several post about the using express.static but I still can't figure out what I messed up. Any help would be greatly appreciated.

Why does it appear that the server can not find the files even though I have them in the locations in the file tree.

Your express setup is fine, HTTP 304 means the browser requested content on server and node/express says is not modified:

http://www.checkupdown.com/status/E304.html

Sounds like your issue is with the client-side code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM