grunt-contrib-connect middleware redirect function. easy to use make fake api for front-end. This sample used yeoman generator gruntfile.
- download
redirect.js
to 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.
rootDir
is fake api root folder.indexFile
is default file. headers is response header for example:
/app
...
/api
/user
index.json
list.json
...
/Gruntfile.js
...
- run
grunt server
- access
/user
will response /api/user/index.json - access
/user/list.json
will response /api/user/list.json
- access