Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 404 for stylesheets and js on sample express-jade project

I have created a simple static page in nodejs using the default express library. However, when I run it, nodejs is unable to pick up the public files and throws 404 on them.

I believe that the paths that I have given are correct. This is driving me mad. I knoww the problem has to be so tiny and simple to be face-palm worthy but I am unable to find it.

Can you please help me here.

The code is on github at Rishavs/ComingSoonPage

Thanks for your time and help.

~ Rishav

like image 806
Rishav Sharan Avatar asked Jan 14 '13 12:01

Rishav Sharan


2 Answers

In your app.js, mount the static files earlier, like so:

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.static(path.join(__dirname, '/public')));
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
});

Edit: Note the in /public VS public

like image 198
Andrei Mustata Avatar answered Oct 12 '22 13:10

Andrei Mustata


Like markt mentioned. Your html should not be referencing "public".

<link href="../../styles/site.css" rel="stylesheet" />

vs.

<link href="../../public/styles/site.css" rel="stylesheet" />
like image 35
tribe84 Avatar answered Oct 12 '22 13:10

tribe84