Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less-middleware not compiling, getting 404

I have a node.js server running with less-middleware. From my understanding, it compiles on the fly and places the css file in the destination/same(if not specified) folder.

My problem is I'm getting a 404 error on the get request for the css file:

Err: GET http://webserver/public/less/blog-reset.css 404 (Not Found)

Here is what I'm working with:

web.js

//requiring dependencies
var express = require("express");
var logfmt = require("logfmt");
var lessMiddleware = require('less-middleware');
var hogan = require('hogan-express');
var path = require('path');

//all environments
var app = module.exports = express();
var port = Number(process.env.PORT || 5000);

app.use(logfmt.requestLogger());
app.use(lessMiddleware(path.join(__dirname,'public')));
app.use(express.static(path.join(__dirname,'public')));
app.set('layout',path.join(__dirname,'src','views','blog-layout'));
app.enable('view cache');
app.engine('.html',hogan);

//page routing called after env loads
require('./src/router');

//listening port
app.listen(port, function() {
  console.log("Listening on " + port);
});

blog-layout.html

<head>
        <title>EpiBlog</title>
        <link href='/public/less/blog-reset.css' rel='stylesheet' type='text/css'/>
</head>
<body>
        {{{yield}}}
</body>

directory layout

ROOT
   public
      less
   src
   web.js

Versions

  • less-middleware v0.2.1-beta
  • express v4.0.0

What I've tried:

  • using app.use(lessMiddleware)({ src: __dirname + '/public' })); (apparently the old way of doing it)
  • using app.use(lessMiddleware(path.join(__dirname,'public','less')));
  • moving app.use(express.static(path.join(__dirname,'public'))); from web.js to router.js
  • toying with different paths
  • moving contents of router.js to web.js
  • specifying the destination using

this:

app.use(lessMiddleware(path.join(__dirname, 'source', 'less'), {
  dest: path.join(__dirname, 'public')
}));
like image 553
13ruce1337 Avatar asked Oct 01 '22 00:10

13ruce1337


1 Answers

the problem was:

<link href='/public/less/blog-reset.css' rel='stylesheet' type='text/css'/>

should have been:

<link href='/less/blog-reset.css' rel='stylesheet' type='text/css'/>

i read that:

link(rel='stylesheet', type='text/css', href='css/styles.css')

was paired with directory structure:

myapp
+-public
  +-css
    +-styles.less

which led me to believe that this call:

app.use(express.static(path.join(__dirname,'public')));

makes the request assume /public/ is the parent so i was being redundant calling /public/less/blog-reset.css

reference was found here: express.js less compiler: can not get work

like image 133
13ruce1337 Avatar answered Oct 13 '22 10:10

13ruce1337