简体   繁体   English

较少中间件未编译,得到404

[英]less-middleware not compiling, getting 404

I have a node.js server running with less-middleware. 我有一个运行较少中间件的node.js服务器。 From my understanding, it compiles on the fly and places the css file in the destination/same(if not specified) folder. 根据我的理解,它会即时编译并将css文件放置在destination / same(如果未指定)文件夹中。

My problem is I'm getting a 404 error on the get request for the css file: 我的问题是,我在css文件的get请求中遇到404错误:

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

Here is what I'm working with: 这是我正在使用的:

web.js 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 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 较少中间件v0.2.1-beta
  • express v4.0.0 快递v4.0.0

What I've tried: 我尝试过的

  • using app.use(lessMiddleware)({ src: __dirname + '/public' })); 使用app.use(lessMiddleware)({ src: __dirname + '/public' })); (apparently the old way of doing it) (显然,这是过去的做法)
  • using app.use(lessMiddleware(path.join(__dirname,'public','less'))); 使用app.use(lessMiddleware(path.join(__dirname,'public','less')));
  • moving app.use(express.static(path.join(__dirname,'public'))); 移动app.use(express.static(path.join(__dirname,'public'))); from web.js to router.js 从web.js到router.js
  • toying with different paths 玩弄不同的路径
  • moving contents of router.js to web.js 将router.js的内容移动到web.js
  • specifying the destination using 使用指定目的地

this: 这个:

app.use(lessMiddleware(path.join(__dirname, 'source', 'less'), {
  dest: path.join(__dirname, 'public')
}));

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 使请求假定/public/是父级,因此我被多余地调用/public/less/blog-reset.css

reference was found here: express.js less compiler: can not get work 在这里找到参考: express.js较少的编译器:无法获得工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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