From 0dce62a39bcada51c66a1dad660e9ce48d0a80ba Mon Sep 17 00:00:00 2001 From: evilgod528 Date: Mon, 23 Jan 2017 14:51:24 +0800 Subject: [PATCH 1/2] support ajax cors --- frontend/etcdbrowser.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/etcdbrowser.js b/frontend/etcdbrowser.js index f1f461a..281b20b 100644 --- a/frontend/etcdbrowser.js +++ b/frontend/etcdbrowser.js @@ -36,7 +36,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ $scope.loadNode = function(node){ delete $scope.error; - $http({method: 'GET', url: $scope.getPrefix() + keyPrefix + node.key}). + $http({withCredentials: true,method: 'GET', url: $scope.getPrefix() + keyPrefix + node.key}). success(function(data) { prepNodes(data.node.nodes,node); node.nodes = data.node.nodes; @@ -72,9 +72,9 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ var value = prompt("Enter Property value", ""); if(!name || name == "") return; - $http({method: 'PUT', - url: $scope.getPrefix() + keyPrefix + node.key + (node.key != "/" ? "/" : "") + name, - params: {"value": value}}). + $http({withCredentials: true,method: 'PUT', + url: $scope.getPrefix() + keyPrefix + node.key + (node.key != "/" ? "/" : "") + name, + params: {"value": value}}). success(function(data) { $scope.loadNode(node); }). @@ -82,7 +82,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ } $scope.updateNode = function(node,value){ - $http({method: 'PUT', + $http({withCredentials: true,method: 'PUT', url: $scope.getPrefix() + keyPrefix + node.key, params: {"value": value}}). success(function(data) { @@ -92,7 +92,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ } $scope.deleteNode = function(node){ - $http({method: 'DELETE', url: $scope.getPrefix() + keyPrefix + node.key}). + $http({withCredentials: true,method: 'DELETE', url: $scope.getPrefix() + keyPrefix + node.key}). success(function(data) { $scope.loadNode(node.parent); }). @@ -103,7 +103,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ var dirName = prompt("Copy property to directory","/"); if(!dirName || dirName == "") return; dirName = $scope.formatDir(dirName); - $http({method: 'PUT', + $http({withCredentials: true,method: 'PUT', url: $scope.getPrefix() + keyPrefix + dirName + node.name, params: {"value": node.value}}). error(errorHandler); @@ -112,7 +112,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ $scope.createDir = function(node){ var dirName = prompt("Enter Directory Name", ""); if(!dirName || dirName == "") return; - $http({method: 'PUT', + $http({withCredentials: true,method: 'PUT', url: $scope.getPrefix() + keyPrefix + node.key + (node.key != "/" ? "/" : "") + dirName, params: {"dir": true}}). success(function(data) { @@ -122,7 +122,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ } $scope.copyDirAux = function(node, tarjet){ - $http({method: 'GET', url: $scope.getPrefix() + keyPrefix + node.key}). + $http({withCredentials: true,method: 'GET', url: $scope.getPrefix() + keyPrefix + node.key}). success(function(data) { prepNodes(data.node.nodes,node); node.nodes = data.node.nodes; @@ -131,7 +131,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ $scope.copyDirAux(node.nodes[key], tarjet + node.nodes[key].name + "/") } else { var url = $scope.getPrefix() + keyPrefix + tarjet + node.nodes[key].name - $http({method: 'PUT', + $http({withCredentials: true,method: 'PUT', url: url, params: {"value": node.nodes[key].value}}). error(errorHandler); @@ -150,7 +150,7 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ $scope.deleteDir = function(node) { if(!confirm("Are you sure you want to delete " + node.key)) return; - $http({method: 'DELETE', + $http({withCredentials: true,method: 'DELETE', url: $scope.getPrefix() + keyPrefix + node.key + "?dir=true&recursive=true"}). success(function(data) { $scope.loadNode(node.parent); @@ -179,19 +179,19 @@ app.controller('NodeCtrl', ['$scope','$http','$cookies', function($scope,$http,$ $scope.loadStats = function(){ console.log("LOAD STATS"); $scope.stats = {}; - $http({method: 'GET', url: $scope.getPrefix() + statsPrefix + "/store"}). + $http({withCredentials: true,method: 'GET', url: $scope.getPrefix() + statsPrefix + "/store"}). success(function(data) { $scope.stats.store = JSON.stringify(data, null, " "); }). error(errorHandler); delete $scope.storeStats; - $http({method: 'GET', url: $scope.getPrefix() + statsPrefix + "/leader"}). + $http({withCredentials: true,method: 'GET', url: $scope.getPrefix() + statsPrefix + "/leader"}). success(function(data) { $scope.stats.leader = JSON.stringify(data, null, " "); }). error(errorHandler); delete $scope.storeStats; - $http({method: 'GET', url: $scope.getPrefix() + statsPrefix + "/self"}). + $http({withCredentials: true,method: 'GET', url: $scope.getPrefix() + statsPrefix + "/self"}). success(function(data) { $scope.stats.self = JSON.stringify(data, null, " "); }). From 5edd78836fb0bfcbe5c5300fcd5d988c5bed692c Mon Sep 17 00:00:00 2001 From: evilgod528 Date: Mon, 23 Jan 2017 15:04:37 +0800 Subject: [PATCH 2/2] refix in other directory can not found the resource dir --- server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index a385235..4619369 100644 --- a/server.js +++ b/server.js @@ -33,7 +33,7 @@ var serverPort = process.env.SERVER_PORT || 8000; var publicDir = 'frontend'; var authUser = process.env.AUTH_USER; var authPass = process.env.AUTH_PASS; - +var serverDir = path.dirname(process.argv[1]); var mimeTypes = { @@ -62,7 +62,8 @@ http.createServer(function serverFile(req, res) { return proxy(req, res); } var uri = url.parse(req.url).pathname; - var filename = path.join(process.cwd(), publicDir, uri); + + var filename = path.join(serverDir, publicDir, uri); fs.exists(filename, function(exists) { // proxy if file does not exist