Skip to content

Instantly share code, notes, and snippets.

@jakobloekke
Created June 11, 2014 13:20
Show Gist options
  • Save jakobloekke/206fb160c0e81c5343ab to your computer and use it in GitHub Desktop.
Save jakobloekke/206fb160c0e81c5343ab to your computer and use it in GitHub Desktop.
Yeoman connect mod-rewrite for Angular html5 routing
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