Giter Club home page Giter Club logo

connect-static's People

Contributors

andrewrk avatar dependabot[bot] avatar rkaw92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

connect-static's Issues

watching fs?

Does this support watching the filesystem for new files added to the directory and/or changes to files that are being statically served? If not, would an update be considered to add that as an option or to make it possible for the user to plug in their own code that implements it?

Does not work with symlinks

Hey.

So I wanted to use this to catch all requests that in production mode will be delivered thru a CDN...whilst doing so, I noticed that this module does not like symlinks. I have two kinds of symlinks:

  • Folders: /cdn/bootstrap-accessibility -> ../node_modules/bootstrap-accessibility-plugin/plugins/
  • Files: /cdn/css/normalize.css -> ../../node_modules/normalize.css/normalize.css

Neither of those got served. I have the same setup for javascript files also. Now, here is what I had to do in order to fix it:

        srvStatic({
            dir: config.base+"/cdn",
            aliases: [ ["/","/index.html"] ],
            ignoreFile: function(fullPath) {
                var basename = path.basename(fullPath);
                return /^\./.test(basename)
                    || /~$/.test(basename)
                    || /^(.+\.php)$/.test(basename);
            }
        }, function(err, middleware) {
            if (err) throw err;
            app.use(vhost(config.BIRD3.url, CDN));
            CDN.use(config.CDN.baseUrl, middleware);
            // Fallback handle for symlinks. Quite the callback hell...
            CDN.use(config.CDN.baseUrl, function(req, res, next){
                // Preps
                var rqFile = config.base+"/cdn"+req.url;
                var mt = mime.types[path.extname(rqFile).substr(1)];
                var rqObj = {"Content-type":mt};
                log.info("Static fallback: "+rqFile+" | "+mt);
                if(err) { next(); throw err; }
                fs.stat(rqFile, function(err,stats){
                    if(err) { throw err; next(); }
                    if(stats.isSymbolicLink()) {
                        fs.readlink(rqFile, function(err, linkstr){
                            if(err) throw err;
                            log.info("--> Redirecting request \""+req.url+"\" to \""+linkstr+"\"");
                            var baseDir = path.dirname(rqFile);
                            var realFile = path.join(baseDir, linkstr);
                            fs.readFile(realFile, function(err, data){
                                if(err) throw err;
                                res.writeHead(200,rqObj);
                                res.end(data);
                            });
                        });
                    } else {
                        fs.readFile(rqFile, function(err, data){
                            if(err) throw err;
                            res.writeHead(200,rqObj);
                            res.end(data);
                        });
                    }
                });
            });
        });

Why aren't symlinks working OOB?

Kind regards, Ingwie

Middleware not called

Being a bit new to Node I can't quite get it to work.
I can see that it scans the files and in theory caches them but it seems the middleware is never called in my setup.

I'm running this in my node server.js file:
createStatic({dir: "app"},
function(err, middleware) {
app.use('/', middleware);
});

Is that correct? Or should it be in my routes? If in my routes then what do I do with my default route for "/"?

mime error

var mimeType = mime.lookup(relName);
                        ^
TypeError: mime.lookup is not a function

I guess you have to replace require 'mime' with 'mime-types'

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.