/************************/
/**** back end express ***/
/************************/
router.get('/download', function(req, res) {
var filename ="";
if(req.query.type =="interior"){
filename="right_interior_design.json"
}
else if(req.query.type =="brand"){
filename="right_brand.json"
}
else if(req.query.type =="category"){
filename="right_category.json"
}
else if(req.query.type =="type"){
filename="right_interior_design_type.json"
}
else if(req.query.type =="space"){
filename="right_space.json"
}
else if(req.query.type =="product"){
filename="right_product.json"
}
else{
res.send("file not found");
}
var filepath = '/home/sig/Archive/' + filename;
// Tricky: do not awaiting for `downloadFileFromAcerCloud` async :)
downloadFileFromAcerCloud(filename);
fs.readFile(filepath, 'utf8', function(err, data) {
if (err) {
res.send(err);
} else {
res.header("Access-Control-Allow-Origin", "*");
res.json(JSON.parse(data));
}
});
})
/************************/
/**** front end angular ***/
/************************/
angular.module('FilterInControllerModule', [])
.controller('Controller', function($scope, $http){
$scope.result
$http.get("http://113.196.236.128:5571/download?type=product").then(
function(resp){
console.log("success");
console.log(resp.data);
// $scope.result=resp.data.results;
$scope.result=resp.data;
},
function(error){
console.log("error");
$scope.result=error;
}
);
/************************/
});
沒有留言:
張貼留言