-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS isn't compiled after the first success? #49
Comments
Thanks for reporting the bug. |
Thanks for responding! I've downgraded to 0.8 and am still seeing the same issue. |
@shawnbot, sorry for being late. As it turned out, this is not a bug its a (sleek) feature! 😎 If the content of Sass source has not changed since the last successful compilation, the middleware will prevent the recompilation. The condition compares the With You can safely remove Please feel free to reopen if you still believe there is a problem. Thanks. |
@am11 Unfortunately, that's not what I'm seeing. The bug described above crops up when I remove % git clone https://github.com/18F/doi-extractives-data.git
% cd doi-extractives-data
% npm install Next edit server.js on line 57 and set Then, start the server and request the stylesheet twice: % npm start
% curl -I http://localhost:6002/css/main.css
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/css
Cache-Control: max-age=0
Date: Mon, 22 Jun 2015 18:04:10 GMT
Connection: keep-alive
% curl -I http://localhost:6002/css/main.css
HTTP/1.1 404 Not Found
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 26
Date: Mon, 22 Jun 2015 18:04:12 GMT
Connection: keep-alive At this point, I can see that % ls -la style/css/main.css
-rw-rw-r-- 1 user blah 90 Jun 22 11:04 main.css The same thing happens when I |
Is it possible that none of the imports was changed and that it's just calling |
I have not worked with middleware architecture much (just used Owin couple of times), but the concept of middleware is to pass on to the next one, and hence the request flow should continue until handled; response is produced. Throwing exceptions or ending the flow happens usually in the finalizer middleware. With that said, In your usage, you can probably do something like: app.use('/css', sass({
src: __dirname + '/styles/sass',
dest: __dirname + '/styles/css',
outputStyle: 'nested',
debug: true,
force: true,
sourceMap: true
}))
.use(function(err, req, res, next) {
if(err) {
res.statusCode = 500;
return res.end(err.message);
}
var destination = _dirname + '/styles/css' + require('url').parse(req.url).pathname;
if(!fs.existsSync(destination )) {
res.statusCode = 404;
return res.end('Compilation failed: Destination file not found.');
}
res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(fs.readFileSync(destination));
}); If this does not satisfy the issue either, please reopen this issue and someone well familiar will investigate. |
Hi there, I've got the same 404 res just like what shawnbot got, Looks like if we don't add "force:true", it won't recompile , and won't sent to client either. |
Hello @cyl19910101, see the related discussion at: #54. |
Thank you very much for responding @am11 , this is kind of a different circumstance from #54, And I figure out why shawnbot and I got the same 404 error while other guys just worked well. That's because we didn't add an extra static file middle ware to read the already exist css file which will be invoke in your code: " changed && changed.length ? compile() : next(); " --We didn't add the next middle ware. And for some other user may have the same problem like me, Might I suggest you that use the same way to handle the response that both send back in node-sass-middleware whether it need to compile, or both use an extra static file middle ware to handle the response? If so, they won't get the css file unless they use a correct static file middle ware setting, Or they can get the css file whether they use a static file middle ware. Maybe simply change the express sample will do too. I'm not good at english, sorry to let you read a post like this~ |
@cyl19910101, thanks for spotting the issue and for the working solution. We should highlight this information in Readme, so in future, other users don't get confused. PR is welcome! :) Regarding using the static file middleware instead of invoking While this is the most common usecase that users would like to have static css file handler put as a next to node-sass-middleware, but IMO it goes against the middleware architecture itself. The idea of middleware is to decide whether you want to handle certain request, if so handle it and return to the next middleware, otherwise return to the next as is immediately, without handling it. Now if we provide an option to override this behavior and chose the next static file middleware, this way node-sass-middleware will act like an API which changes the control behavior based on the option, instead of being a lightweight middleware -- exercising the principle separation of concerns. Note that the existing If you still think this would be a good idea to have another exceptional option like |
I'm having the same issue as @shawnbot: Upon the first request, the Here's my express setup: app.use(sassMiddleware({
src: path.join(__dirname, 'views'),
dest: path.join(__dirname, 'public'),
indentedSyntax: true,
prefix: '/public',
debug: true,
outputStyle: 'expanded'
}))
app.use(express.static(path.join(__dirname, 'public'))) First request: $ rm -f public/style.css
# At this point the server is started
$ curl http://localhost:3000/public/style.css
h1 {
color: red;
}
$ ls public/style.css
public/style.css Corresponding output on the server log:
Next request: $ curl http://localhost:3000/public/style.css
Cannot GET /public/style.css Corresponding server log:
Removing the compiled $ rm public/style.css
$ curl http://localhost:3000/public/style.css
h1 {
color: red;
}
$ curl http://localhost:3000/public/style.css
Cannot GET /public/style.css Similarly, restarting the server (without removing a previously compiled # Restart server here
$ ls public/style.css
public/style.css
$ curl http://localhost:3000/public/style.css
h1 {
color: red;
}
$ curl http://localhost:3000/public/style.css
Cannot GET /public/style.css If I add $ curl http://localhost:3000/public/style.css
h1 {
color: red;
}
$ curl http://localhost:3000/public/style.css
h1 {
color: red;
} However, I don't think There's a similar (unanswered) question on StackOverflow regarding this behavior. I'm using node-sass-middleware 0.10.0 with express 4.14.0. |
@torfsen, does it work if you replace: app.use(express.static(path.join(__dirname, 'public'))) with: app.use('/public', express.static(path.join(__dirname, 'public'))) See a working example at: #70 (comment) and working project at #70 (comment). |
I'm running into a weird issue using this middleware with Express. Here is our usage:
Our issue is that if we don't pass
force: true
, the CSS for our source file only compiles successfully the first time, and 404s after that. I've cloned the repo and added a test case that attempts to simulate this by simply requesting a stylesheet twice in a row, but I can't reproduce it.Here's what happens on the console:
The first request outputs the sass middleware's debug messages, as expected:
The second time around, nothing happens and Express returns a 404.
The third time around, the middleware outputs just the source and dest paths, but no render calls:
I can try to create a standalone test case for this if you'd like, but I just wanted to make sure that I'm not doing something glaringly wrong or missing something totally obvious. As you can see, there's nothing very complex going on in our SCSS source. Thank you!
The text was updated successfully, but these errors were encountered: