grunt-contrib-connect middleware redirect function. easy to use make fake api for front-end. This sample used yeoman generator gruntfile.
- download
redirect.jsto project root. - edit
Gruntfile.js
var redirect = require('./redirect');
...
...
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function(connect) {
return [
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app'),
redirect('api')
];
}
}
}
},- the redirect with 3 arguments.
rootDiris fake api root folder.indexFileis default file. headers is response header for example:
/app
...
/api
/user
index.json
list.json
...
/Gruntfile.js
...- run
grunt server- access
/userwill response /api/user/index.json - access
/user/list.jsonwill response /api/user/list.json
- access