forked from balderfer/pley-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.67 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
const express = require('express');
const app = express();
const request = require('request');
// Set up bodyParser.
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.post('/new-app', (req, res, next) => {
if (!req.body.githubURL || !req.body.subdomain || !req.body.userId) {
console.log('POST request is missing something important');
console.log('req.body', req.body);
return res.status(400).end();
}
console.log('got data in /new-app');
console.log('req.body.githubURL', req.body.githubURL);
console.log('req.body.subdomain', req.body.subdomain);
console.log('req.body.userId', req.body.userId);
const url = 'http://bart.usb.cs.purdue.edu:3000/new-app';
request.post(url, {
form: {
githubURL: req.body.githubURL,
subdomain: req.body.subdomain,
userId: req.body.userId
}
}, (error, response, body) => {
if (!error) {
console.log('response body', body);
res.status(200).end();
} else {
console.log('Error!', error);
res.status(500).end();
}
});
});
app.get('/app-data', (req, res, next) => {
if (!req.query.userId) {
console.log('GET request is missing something important');
return res.status(400).end();
}
const url = 'http://bart.usb.cs.purdue.edu:3000/app-data?userId=' + req.query.userId;
request.get(url, (error, response, body) => {
if (!error) {
console.log('response body', body);
res.status(200).send(response.body);
} else {
console.log('Error!', error);
res.status(500).end();
}
});
});
app.listen(8080, () => {
console.log("I'm alive!");
});