-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (50 loc) · 1.29 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
process.env.NTBA_FIX_319 = true
const serverless = require('serverless-http');
const express = require('express');
const bodyParser = require('body-parser');
var cors = require('cors');
const githubAPI = require('./utils/githubAPI')
const telegramBot = require('./utils/telegramBot')
const app = express();
app.use(cors());
app.use(bodyParser.json({ strict: false }));
/*
** Routes
*/
app.get('/', (req, res) => {
return res.send('working...');
})
// Get github rate limit
app.get('/github/rate_limit', (req, res) => {
return githubAPI.rateLimit()
.then(res.json.bind(res))
})
// Get all jobs from a category
app.get('/github/jobs/:category', (req, res) => {
return githubAPI
.fetchJobsByCategory(req.params.category)
.then(res.json.bind(res))
.catch(error =>
res.status(404).json({
error: error.message
})
);
})
// Get a job from a repository
app.get('/github/jobs/repository/:repository/:jobId', (req, res) => {
const {
repository,
jobId,
} = req.params
return githubAPI
.fetchJob(repository, jobId)
.then(res.json.bind(res))
.catch((error) => res.status(404).json({
error: error.message,
}))
})
app.get('/spread-the-word', (req, res) => {
telegramBot()
res.sendStatus(200)
})
module.exports.handler = serverless(app);