-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (36 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const skygearCloud = require('skygear/cloud');
const SkygearResponse = skygearCloud.SkygearResponse;
const requestResolver = require('./src/request-resolver');
const GitHubRepo = require('./src/GitHubRepo');
let serverStatus = 'Initializing....';
try {
const githubRepo = new GitHubRepo('https://api.github.com/',
process.env.GITHUB_REPO,
null
);
githubRepo.fetchReleases().then(function() {
serverStatus = 'GitHub repo connected!';
skygearCloud.handler('update', function (req) {
return requestResolver.resolve(githubRepo, req.query.version, req.query.platform).then(result => {
return new SkygearResponse({
statusCode: result.statusCode,
body: JSON.stringify(result.body)
});
});
}, {
method: ['GET', 'POST'],
userRequired: false
});
}).catch(function() {
serverStatus = 'Connection with GitHub repo failed. Please make sure environment variable - GITHUB_REPO - is a valid GitHub repo.';
});
} catch (e) {
serverStatus = 'Environment variables GITHUB_REPO not set';
}
skygearCloud.handler('getStatus', function() {
return 'Server Status: ' + serverStatus;
}, {
method: ['GET', 'POST'],
userRequired: false
});