jussi-kalliokoski / gulp-awspublish-router

A router for defining file-specific rules with gulp-awspublish

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom mime types

skyzyx opened this issue · comments

I'm using aws publish + the router to upload some assets. Is there any way to override the default mime types from the mime package here?

@Skyzyz: Sure! You can manually override the Content-Type header in your route configuration, for example:

...
routes: {
  "\.moo$": {
    key: "$&",
    headers: {
      "Content-Type": "application/moo",
    },
},
...

Closing, but feel free to follow up if there's anything. :)

It's not actually working for me.

  1. I completely deleted the contents of my S3 bucket.
  2. I ran gulp deploy-static.
  3. Upon completion, I inspected the content-type values for each of the files.
  • css files had the correct text/css; charset=utf-8.
  • js files had the wrong application/javascript.
  • cssz and jsz files had the wrong application/octet-stream.
  • ttf, woff and woff2 files had the wrong application/font-* prefix instead of the correct application/x-font-* prefix.

Here's my gulpfile.js:

var gulp = require('gulp')
  , AWS = require('aws-sdk')
  , awspublish = require('gulp-awspublish')
  , awspublishRouter = require('gulp-awspublish-router')
  , fs = require('fs')
  , parallelize = require('concurrent-transform')
  , rename = require('gulp-rename')
;

//------------------------------------------------------------------------------

gulp.task('deploy-static', function() {
    var publisher = awspublish.create(
        JSON.parse(fs.readFileSync('aws-credentials.json', 'utf8'))
    );

    gulp.src("**/*", { cwd: "./public/s/" })
        .pipe(rename(function (path) {
            path.dirname = '/s/' + path.dirname;
        }))
        .pipe(awspublishRouter({
            cache: {
                cacheTime: 604800,
                useExpires: true
            },
            routes: {
                "\.css$": {
                    key: "$&",
                    headers: {
                        "Content-Type": "text/css; charset=utf-8"
                    }
                },
                "\.cssz$": {
                    key: "$&",
                    headers: {
                        "Content-Encoding": "gzip",
                        "Content-Type": "text/css; charset=utf-8"
                    }
                },
                "\.eot$": {
                    key: "$&",
                    headers: { "Content-Type": "application/vnd.ms-fontobject" }
                },
                "\.js$": {
                    key: "$&",
                    headers: {
                        "Content-Type": "text/javascript; charset=utf-8"
                    }
                },
                "\.jsz$": {
                    key: "$&",
                    headers: {
                        "Content-Encoding": "gzip",
                        "Content-Type": "text/javascript; charset=utf-8"
                    }
                },
                "\.svg$": {
                    key: "$&",
                    headers: {
                        "Content-Type": "image/svg+xml"
                    }
                },
                "\.svgz$": {
                    key: "$&",
                    headers: {
                        "Content-Encoding": "gzip",
                        "Content-Type": "image/svg+xml"
                    }
                },
                "\.ttf$": {
                    key: "$&",
                    headers: { "Content-Type": "application/x-font-ttf" }
                },
                "\.woff$": {
                    key: "$&",
                    headers: { "Content-Type": "application/x-font-woff" }
                },
                "\.woff2$": {
                    key: "$&",
                    headers: { "Content-Type": "application/x-font-woff2" }
                },
                "^.+$": "$&"
            }
        }))
        .pipe(
            parallelize(
                publisher.publish({
                    'Cache-Control': 'max-age=315360000, no-transform, public',
                    'Expires': function() {
                        var date = new Date();
                        date.setDate(date.getDate() + 7); // 7 days
                        return date;
                    }()
                })
            ), 10
        )
        .pipe(publisher.sync())
        // .pipe(publisher.cache())
        .pipe(awspublish.reporter())
    ;
});

What am I doing wrong?

ping

Sorry for the delay! Hmm, probably the internals of gulp-awspublish have changed since I made this - would have to update to match the latest version. Unfortunately I don't currently have time to figure that out myself, so PRs accepted, sorry. :/

@skyzyx @jussi-kalliokoski I believe this to be an issue in gulp-awspublish and have opened a PR.

@skyzyx you can try again with Version 1.0.8 of gulp-awspublish; PR was just merged. Thanks @pgherveou.