Coder Social home page Coder Social logo

Comments (7)

jameswyse avatar jameswyse commented on September 1, 2024

Okay so it seems it was hitting incompatible files in my views/public folder, so I moved the next(); call to outside the if block.

    walker.on('file', function(root, stat, next) {
      var ext = path.extname(stat.name), text;
      if (ext === '.jade' || ext === '.ejs') {
        fs.readFile(path.join(root, stat.name), 'utf8', function(err, data) {
          if (err) throwError(err);
          var match;
          while( (match = regexCDN.exec(data)) ) {
            results.push(match[1]);
          }
          //next();
        });
      }
      next();
    });

Which works (sent a separate pull request [#5]) , however now I have a problem where the filename in the link tag is different to the uploaded file

layout.jade

!= CDN(['/stylesheets/bootstrap.min.css', '/stylesheets/admin.css', '/stylesheets/chosen.css'])

Produces:

<link href="http://d2fzxitfbadxdo.cloudfront.net/bootstrap.min.css%2Badmin.css%2Bchosen.4018685863000.css" rel="stylesheet" />

however the file uploaded is named bootstrap.min.css+admin.css+chosen.4018684931000.css

On server start it uploads the stylesheets every time with a different name.

note: javascripts are uploading and rendering correctly, which I find strange as the timestamp/versioning code seems to be the same for both. Any ideas here?

from express-cdn.

niftylettuce avatar niftylettuce commented on September 1, 2024

The timestamps stuff works for multiple files by adding the individual fs.statSync.mtime.getTime() values together, then if the asset was not found on S3, it will re-upload the asset. It would seem to me in this case that one or more of those stylesheets is changing every time you start the server upon express-cdn issuing a http GET request to the URL of the local asset. I used an http GET request so that users could continue utilizing their existing stylesheet compilers.

from express-cdn.

niftylettuce avatar niftylettuce commented on September 1, 2024

I have to actually unroll your change because it is outside the callback for fs.readFile and therefore would not work.

from express-cdn.

jameswyse avatar jameswyse commented on September 1, 2024

Aha that makes sense, I forgot I had stylus middleware in my production environment. Removing it fixes the issue.

I'm not sure about the next() problem, it seems to work as expected where I have placed it. I've never used the walk library, am I incorrect that walker.on('file') is called for every file as it walks the directory and that next(); causes it to go on to the next file?

from express-cdn.

niftylettuce avatar niftylettuce commented on September 1, 2024

I fixed the next() issue -- yes the next(); goes to the next file -- here is the documention if you want to read more about it https://github.com/coolaj86/node-walk/.

Btw added @jameswyse and @emostar as contributors on Readme.md and package.json.

from express-cdn.

niftylettuce avatar niftylettuce commented on September 1, 2024

Fixed it by simply adding: } else { next();.

30188b1

from express-cdn.

jameswyse avatar jameswyse commented on September 1, 2024

That makes sense. I need a coffee.

Cheers, great work!

from express-cdn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.