Running yeoman server does not seem to recognize the .htaccess file by default. Is there an additional step to enable reading of the .htaccess file?
Here are the lines I have uncommented with no apparent affect in setting headers after restarting:
# ----------------------------------------------------------------------
# Cross-domain AJAX requests
# ----------------------------------------------------------------------
# Serve cross-domain Ajax requests, disabled by default.
# enable-cors.org
# code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Or maybe the proper question is how would one set headers when running yeoman server? Is there another option, perhaps in Gruntfile.js?
grunt server is just a Node.js connect server and doesn't support .htaccess
Though since grunt-contrib-connect supports custom middlewares you can add this to your Gruntfile.js:
var corsMiddleware = 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();
}
grunt.initConfig({
connect: {
server: {
options: {
middleware: function(connect, options) {
return [
// Serve static files
connect.static(options.base),
// Make empty directories browsable
connect.directory(options.base),
// CORS support
corsMiddleware
];
}
}
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With