Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display PDF in browser through grunt-contrib-connect

I'm running an AngularJS app and I'm using the grunt-contrib-connect plugin to host my stuff. I'd like some PDF files to be accessed in the browser (tested in all of them), but the pages stay blank. It does show the correct amount of pages, though. I've exported the PDF from a .doc-file using both Word and Pages, but the result stays the same.

I wrote this little middleware snippet to ensure the headers are set (and they are, according to Chrome's Network tab), but the pages stay blank. Any help?

In my Gruntfile;

grunt.initConfig({
    settings: {}, // ...
    connect: {
        livereload: {
            middleware: function(connect) {
                var middlewares = [];
                // Other middlewares
                middlewares.push(function (req, res, next) {
                    if (~req.url.indexOf('.pdf')) {
                        res.setHeader('Content-type', 'application/pdf');
                    }
                    return next();
                });

                return middlewares;
            }
        } 
    } 
});
like image 954
Nick Avatar asked May 08 '14 09:05

Nick


1 Answers

It seems grunt-contrib-connect has problems serving binary files: https://github.com/gruntjs/grunt-contrib-connect/issues/142

like image 50
geon Avatar answered Sep 19 '22 06:09

geon