Skip to content

Commit

Permalink
Merge pull request #107 from StrikeForceZero/fix-fonts
Browse files Browse the repository at this point in the history
Fix not being able to serve fonts and other assets using query string cache busters.
  • Loading branch information
jakemmarsh committed Nov 9, 2015
2 parents 77027da + 7df2726 commit 6abbbeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 14 additions & 0 deletions gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ export default {
dest: 'build/fonts'
},

assetExtensions: [
'js',
'css',
'png',
'jpe?g',
'gif',
'svg',
'eot',
'otf',
'ttc',
'ttf',
'woff2?'
],

views: {
index: 'app/index.html',
src: 'app/views/**/*.html',
Expand Down
7 changes: 3 additions & 4 deletions gulp/tasks/browserSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import gulp from 'gulp';
gulp.task('browserSync', function() {

const DEFAULT_FILE = 'index.html';
const ASSET_EXTENSIONS = ['js', 'css', 'png', 'jpg', 'jpeg', 'gif'];
const ASSET_EXTENSION_REGEX = new RegExp(`\\b(?!\\?)\\.(${config.assetExtensions.join('|')})\\b(?!\\.)`, 'i');

browserSync.init({
server: {
baseDir: config.buildDir,
middleware: function(req, res, next) {
let fileHrefArray = url.parse(req.url).href.split('.');
let fileExtension = fileHrefArray[fileHrefArray.length - 1];
let fileHref = url.parse(req.url).href;

if ( ASSET_EXTENSIONS.indexOf(fileExtension) === -1 ) {
if ( !ASSET_EXTENSION_REGEX.test(fileHref) ) {
req.url = '/' + DEFAULT_FILE;
}

Expand Down

0 comments on commit 6abbbeb

Please sign in to comment.