Skip to content

Commit

Permalink
setup qcloud sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
miusuncle committed Oct 13, 2016
1 parent 8ab17de commit 0104024
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
12 changes: 1 addition & 11 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
'use strict';

require('./globals');
require('./setup-qcloud-sdk');

const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const config = require('./config');

// 配置 SDK BEGIN
const qcloud = require('qcloud-weapp-server-sdk');

qcloud.config({
SecretKey: 'eeb93ecd-ecb3-4c58-a347-8ce3617b8e8c',
ServerHost: 'www.qcloua.la',
AuthServerHost: 'http://mina.auth.com:7575',
TunnelServerHost: 'https://ws.qcloud.com',
});
// 配置 SDK END

const app = express();

app.set('query parser', 'simple');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"express": "^4.14.0",
"lodash": "^4.16.1",
"morgan": "^1.7.0",
"qcloud-weapp-server-sdk": "~0.2.0"
"qcloud-weapp-server-sdk": "latest"
}
}
43 changes: 43 additions & 0 deletions setup-qcloud-sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const os = require('os');
const fs = require('fs');
const qcloud = require('qcloud-weapp-server-sdk');

const sdkConfig = (() => {
// Windows
if (os.type().toLowerCase().startsWith('windows')) {
return 'C:\\qcloud\\sdk.config';
}

// Linux
return '/etc/qcloud/sdk.config';
})();

try {
const stats = fs.statSync(sdkConfig);

if (!stats.isFile()) {
throw new Error('File not exists.');
}
} catch (e) {
debug(`SDK 配置文件(${sdkConfig})不存在`);
process.exit(1);
}

const config = (() => {
try {
const content = fs.readFileSync(sdkConfig, 'utf8');
return JSON.parse(content);
} catch (e) {
debug(`SDK 配置文件(${sdkConfig})内容不合法`);
process.exit(1);
}
})();

qcloud.config({
ServerHost: config.serverHost,
AuthServerUrl: config.authServerUrl,
TunnelServerUrl: config.tunnelServerUrl,
TunnelSignatureKey: config.tunnelSignatureKey,
});

debug('[当前 SDK 使用配置] =>', config);

0 comments on commit 0104024

Please sign in to comment.