This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
201 lines (189 loc) · 5.46 KB
/
routes.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const express = require('express')
const router = new express.Router()
const axios = require('axios')
const {
getContributors,
getGuides,
getGuide,
getOverview,
getPartners,
getProduct,
getProducts,
getWcGetStarted,
getWcContribute,
getWcCommunity,
getWcDocs,
} = require('./utils')
router.get('/', (req, res) => {
res.send({
message:
'Welcome to the Elixir Cloud & AAI API. Browse the below routes.',
elixirCloudAai: {
overview: {
message: 'Get the overview page',
path: '/overview',
},
contributors: {
message: 'Get all contributors',
path: '/contributors',
},
guide: {
message: 'Get a guide by id',
path: '/guide/:id',
},
guides: {
message: 'Get all guides',
path: '/guides',
},
partners: {
message: 'Get all partners',
path: '/partners',
},
product: {
message: 'Get a product by id',
path: '/product/:id',
},
products: {
message: 'Get all products',
path: '/products',
},
news: {
message: 'Get all news',
path: '/news',
params: {
next_token: {
message: 'Get next page of news',
path: '/news?next_token=:nextToken',
},
},
},
},
webComponent: {
getStarted: {
message: 'Get all get started guides',
path: '/wc/get-started',
},
community: {
message: 'Get all community guides',
path: '/wc/community',
},
contribute: {
message: 'Get all contribute guides',
path: '/wc/contribute',
},
documentation: {
message: 'Get all documentation guides',
path: '/wc/docs/:query',
},
},
})
})
router.get('/contributors', async (req, res) => {
try {
const data = await getContributors()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/guide/:id', async (req, res) => {
try {
const data = await getGuide(req.params.id)
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/guides', async (req, res) => {
try {
const data = await getGuides()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/news', async (req, res) => {
try {
const config = {
headers: { Authorization: `Bearer ${process.env.TWITTER_TOKEN}` },
}
const query =
'(%23elixir_cloud_aai OR %23elixircloudaai OR %23elixircloud_aai OR @ELIXIRcloud_aai has:mentions) OR ((%23cloudaai OR %23cloud_aai) (%23elixir OR %23elixireurope OR @ELIXIREurope has:mentions))'
const nextValid = req.query.nextToken
? `&next_token=${req.query.nextToken}`
: ''
const response = await axios.get(
`https://api.twitter.com/2/tweets/search/recent?query=${query}${nextValid}`,
config
)
return res.send(response.data)
} catch (e) {
console.log(e)
return res.send({ message: 'Server error', error: e })
}
})
router.get('/overview', async (req, res) => {
try {
const data = await getOverview()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/partners', async (req, res) => {
try {
const data = await getPartners()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/product/:id', async (req, res) => {
try {
const data = await getProduct(req.params.id)
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/products', async (req, res) => {
try {
const data = await getProducts()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/wc/get-started', async (req, res) => {
try {
const data = await getWcGetStarted()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/wc/contribute', async (req, res) => {
try {
const data = await getWcContribute()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/wc/community', async (req, res) => {
try {
const data = await getWcCommunity()
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
router.get('/wc/docs/:query', async (req, res) => {
try {
const data = await getWcDocs(req.params.query)
return res.send(data)
} catch (e) {
return res.send({ message: 'Server error', error: e })
}
})
module.exports = router