-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (28 loc) · 920 Bytes
/
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
"use strict";
const https = require('https');
const http = require('http');
const url = require('url');
const apiKey = process.env.MEETUP_API_KEY || "PLEASE SET YOUR API KEY";
const route = '/meetup/';
const server = http.createServer((req, res) => {
const reqUrl = url.parse(req.url);
const path = reqUrl.pathname
if (path.indexOf(route) != 0) {
res.statusCode = 404;
res.end();
return;
}
const search = reqUrl.search;
const meetupPath = path.substr(route.length);
const meetupUrl = "https://api.meetup.com/" + meetupPath + (search ? search + "&" : "?") + "key=" + apiKey;
console.log(`Making request to ${meetupUrl}`);
https
.get(meetupUrl, apiRes => apiRes.pipe(res))
.on('error', err => {
console.error(err);
res.statusCode = 500;
res.write('Could not make meetup request');
res.end();
}).end();
});
server.listen(process.env.PORT || 3000);