aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@nebulon.de>2015-07-01 02:56:26 +0200
committerJohannes Zellner <johannes@nebulon.de>2015-07-01 02:56:26 +0200
commit9417673303b88aba41fe6a3a8cfd30b1a786b961 (patch)
treeebb7d61bceee2fcab2da8a6b28260797b54dc1ff
parent2594ccd4a578368aa1687e8db708c1cff03491dc (diff)
downloadSurfer-9417673303b88aba41fe6a3a8cfd30b1a786b961.tar.gz
Surfer-9417673303b88aba41fe6a3a8cfd30b1a786b961.tar.zst
Surfer-9417673303b88aba41fe6a3a8cfd30b1a786b961.zip
Parse uri
-rw-r--r--cli/actions.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/cli/actions.js b/cli/actions.js
index 043909d..c8b5c33 100644
--- a/cli/actions.js
+++ b/cli/actions.js
@@ -10,6 +10,7 @@ var superagent = require('superagent'),
10 readlineSync = require('readline-sync'), 10 readlineSync = require('readline-sync'),
11 async = require('async'), 11 async = require('async'),
12 fs = require('fs'), 12 fs = require('fs'),
13 url = require('url'),
13 path = require('path'); 14 path = require('path');
14 15
15require('colors'); 16require('colors');
@@ -48,8 +49,11 @@ function collectFiles(filesOrFolders) {
48 return tmp; 49 return tmp;
49} 50}
50 51
51function login(server) { 52function login(uri) {
52 if (server[server.length-1] === '/') server = server.slice(0, -1); 53 var tmp = url.parse(uri);
54 if (!tmp.host) tmp = url.parse('https://' + uri);
55
56 var server = 'https://' + tmp.host;
53 57
54 console.log('Using server', server); 58 console.log('Using server', server);
55 59
@@ -57,6 +61,10 @@ function login(server) {
57 var password = readlineSync.question('Password: ', { hideEchoBack: true }); 61 var password = readlineSync.question('Password: ', { hideEchoBack: true });
58 62
59 superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { 63 superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) {
64 if (error && error.code === 'ENOTFOUND') {
65 console.log('No such server %s'.red, server);
66 process.exit(1);
67 }
60 if (result.status === 401) { 68 if (result.status === 401) {
61 console.log('Login failed.'); 69 console.log('Login failed.');
62 process.exit(1); 70 process.exit(1);
@@ -70,7 +78,7 @@ function login(server) {
70 78
71 gQuery = { username: username, password: password }; 79 gQuery = { username: username, password: password };
72 80
73 console.log('Done'); 81 console.log('Done'.green);
74 }); 82 });
75} 83}
76 84