Created
June 11, 2014 13:20
-
-
Save jakobloekke/206fb160c0e81c5343ab to your computer and use it in GitHub Desktop.
Yeoman connect mod-rewrite for Angular html5 routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connect: { | |
options: { | |
port: 9000, | |
// Change this to '0.0.0.0' to access the server from outside. | |
hostname: '0.0.0.0', | |
middleware: function (connect, options) { | |
var middlewares = []; | |
var directory = options.directory || options.base[options.base.length - 1]; | |
// enable Angular's HTML5 mode | |
middlewares.push( | |
require('connect-modrewrite')(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.woff$ /index.html [L]']) | |
); | |
if (!Array.isArray(options.base)) { | |
options.base = [options.base]; | |
} | |
options.base.forEach(function (base) { | |
// Serve static files. | |
middlewares.push(connect.static(base)); | |
}); | |
// Make directory browse-able. | |
middlewares.push(connect.directory(directory)); | |
// CORS | |
middlewares.push(function(req, res, next) { | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); | |
res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); | |
next(); | |
}); | |
return middlewares; | |
}, | |
livereload: 35729 | |
}, | |
livereload: { | |
options: { | |
open: true, | |
base: [ | |
'.tmp', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
test: { | |
options: { | |
port: 9001, | |
base: [ | |
'.tmp', | |
'test', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
dist: { | |
options: { | |
base: '<%= yeoman.dist %>' | |
} | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment