custom server

This commit is contained in:
life
2015-03-15 22:38:35 +08:00
parent aba15ad087
commit 238223d7b4
23 changed files with 219 additions and 56 deletions

9
node_modules/api.js generated vendored
View File

@@ -51,8 +51,9 @@ var Api = {
// 是否断网
unConnected: function(error) {
var me = this;
// console.log(error);
if(error && (error.code == "ECONNREFUSED" || error.code == 'ECONNRESET')) { // socket hand up
console.error('---------------------')
console.error(error);
Web.unConnected();
return true;
}
@@ -79,9 +80,12 @@ var Api = {
return url;
},
// 登录
auth: function(email, pwd, callback) {
auth: function(email, pwd, host, callback) {
var me = this;
// 设置server host
Evt.setHost(host);
// log({emai: email, pwd: pwd});
console.log(this.getUrl('auth/login', {email: email, pwd: pwd}));
// console.log('????????????')
@@ -97,6 +101,7 @@ var Api = {
// console.log(ret);
if(Common.isOk(ret)) {
ret.Pwd = pwd;
ret['Host'] = Evt.leanoteUrl;
User.setCurUser(ret);
callback && callback(ret);
} else {

19
node_modules/evt.js generated vendored
View File

@@ -16,12 +16,27 @@ if(!fs.existsSync(dataBasePath)) {
// dataBasePath = '';
var Evt = {
// leanoteUrl: 'http://leanote.com',
leanoteUrl: 'http://localhost:9000',
defaultUrl: 'http://leanote.com',
leanoteUrl: 'http://leanote.com',
// leanoteUrl: 'http://localhost:9000',
setHost: function(host) {
if(!host) {
this.leanoteUrl = this.defaultUrl;
} else {
this.leanoteUrl = host;
}
},
getHost: function() {
return this.leanoteUrl;
},
port: 8008,
localUrl: 'http://127.0.0.1:8008',
dataBasePath: '',
getImageLocalUrl: function(fileId) {
return this.localUrl + '/api/file/getImage?fileId=' + fileId;
},

6
node_modules/user.js generated vendored
View File

@@ -23,6 +23,7 @@ User = {
userId: '',
email: '',
username: '',
host: '', // 服务
LastSyncUsn: -1,
LastSyncTime: null,
// 登录后保存当前
@@ -33,6 +34,7 @@ User = {
this.userId = user.UserId;
this.email = user.Email;
this.username = user.Username;
this.host = user.Host; // http://leanote.com, http://localhost
// 保存到数据库中
this.saveCurUser(user);
@@ -40,6 +42,7 @@ User = {
me.setUserDataPath();
}
},
// 不同host的userId可能一样, 潜在的bug
saveCurUser: function(user, callback) {
// 当前用户是否在数据库中
db.users.count({_id: user.UserId}, function(err, count) {
@@ -101,6 +104,9 @@ User = {
me.username = user.Username;
me.LastSyncUsn = user.LastSyncUsn;
me.LastSyncTime = user.LastSyncTime;
me.host = user.Host;
Evt.setHost(me.host);
// 全局配置也在user中, 到web端
for(var i in me.g) {