Commit 94176733 by Johannes Zellner

Parse uri

1 parent 2594ccd4
Showing with 11 additions and 3 deletions
...@@ -10,6 +10,7 @@ var superagent = require('superagent'), ...@@ -10,6 +10,7 @@ var superagent = require('superagent'),
readlineSync = require('readline-sync'), readlineSync = require('readline-sync'),
async = require('async'), async = require('async'),
fs = require('fs'), fs = require('fs'),
url = require('url'),
path = require('path'); path = require('path');
require('colors'); require('colors');
...@@ -48,8 +49,11 @@ function collectFiles(filesOrFolders) { ...@@ -48,8 +49,11 @@ function collectFiles(filesOrFolders) {
return tmp; return tmp;
} }
function login(server) { function login(uri) {
if (server[server.length-1] === '/') server = server.slice(0, -1); var tmp = url.parse(uri);
if (!tmp.host) tmp = url.parse('https://' + uri);
var server = 'https://' + tmp.host;
console.log('Using server', server); console.log('Using server', server);
...@@ -57,6 +61,10 @@ function login(server) { ...@@ -57,6 +61,10 @@ function login(server) {
var password = readlineSync.question('Password: ', { hideEchoBack: true }); var password = readlineSync.question('Password: ', { hideEchoBack: true });
superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) {
if (error && error.code === 'ENOTFOUND') {
console.log('No such server %s'.red, server);
process.exit(1);
}
if (result.status === 401) { if (result.status === 401) {
console.log('Login failed.'); console.log('Login failed.');
process.exit(1); process.exit(1);
...@@ -70,7 +78,7 @@ function login(server) { ...@@ -70,7 +78,7 @@ function login(server) {
gQuery = { username: username, password: password }; gQuery = { username: username, password: password };
console.log('Done'); console.log('Done'.green);
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!