I am using grunt
connect server with all those livereload
plugins. Developing process was very fast till I added some rest calls. I decided to make some example JSON
files which ll be rest calls answers.
So I need to redirect every rest call to some static
folder(important I ll put it in target folder) so it ll be outside the Angular folder.
So I need some plugin
which transfer calls like:
http.get(localhost:port/x/y/name) to target/jsons_examples/x/y/name.json
http.get(localhost:port/z/name) to target/jsons_examples/z/name.json
grunt file:(1 aplication server, 1 mocking webservices)
grunt.initConfig({
connect: {
all: {
options: {
port: 10100,
hostname: "0.0.0.0",
livereload: true
}
},
webservices_mock: {
options: {
port: 8081,
hostname: "0.0.0.0",
middleware: function(connect, options, middlewares) {
middlewares.unshift(function(req, res, next) {
var pattern = new RegExp('\/rest\/[a-zA-Z0-9\/.]+', 'i'),
matches = req.url.match(pattern);
if (!matches) {
return next();
}
req.setEncoding('utf8');
res.writeHead(200, {"Content-Type": "application/json"});
res.write(grunt.file.read(req.url.replace("/rest", "json_contracts") + "/example.json"));
res.end();
});
return middlewares;
}
}
}
},
...
And now i need in web services mock configuration change the path from json_contracts to path outside angular folder smth like: ././././target/json_contracts