Reputation: 5104
I have an express server:
//setup Dependencies
var connect = require('connect')
, express = require('express')
, port = (process.env.PORT || 8081);
//DB Setup removed for brevity
var server = express.createServer();
server.configure(function(){
server.set('views', __dirname + '/views');
server.set('view engine', 'jade')
server.set('view options', { layout: false });
server.use(connect.bodyParser());
server.use(server.router);
server.use(express.static(__dirname + '/public'));
});
And the home page view:
server.get('/', function(req,res){
res.render('index');
});
Where my folder structure is:
server.js
/views/index.jade
/public/stylesheets/bootstrap.min.css
/public/javascripts/bootstrap.js
However when I try to hit /stylesheets/bootstrap.min.css or /public/stylesheets/bootstrap.min.css I get a 404. Form the examples I can find in the express.js github repo I think I'm setting things up correctly... but I'm clearly missing something.
Upvotes: 1
Views: 925
Reputation: 14013
i get it working whith these conf:
server.use(express.static(__dirname + 'public')); ---> remove the "/"
and in your <head>
request the files like these:
<link rel="stylesheet" href="/stylesheets/bootstrap.min.css">
the full url should be http://example.com/stylesheets/bootstrap.min.css
Upvotes: 1