我正在使用grunt
带有所有这些livereload
插件的连接服务器。开发过程非常快,直到我添加了一些休息电话。我决定制作一些示例JSON
文件,这些文件将作为休息电话的答案。
所以我需要将每个休息调用重定向static
到某个文件夹(重要的是我会把它放在目标文件夹中)所以它会在Angular文件夹之外。
所以我需要一些plugin
转接电话,例如:
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 文件:(1 个应用服务器,1 个模拟 Web 服务)
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;
}
}
}
},
...
现在我需要在 Web 服务模拟配置中将路径从 json_contracts 更改为 angular 文件夹之外的路径,例如:././././target/json_contracts