-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |