-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (36 loc) · 1.08 KB
/
server.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
var express = require('express'),
fetch = require('node-fetch'),
app = express(),
cors = require('cors'),
server = require('http').createServer(app);
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.use(cors());
app.post("/shorten", (req, res) => {
fetch("http://impraise-shorty.herokuapp.com/shorten", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(req.body)
}).then((response) => {
return response.json();
}).then((data) => {
res.send(data);
});
});
app.get("/stats/:shortcode", (req, res) => {
const url = `http://impraise-shorty.herokuapp.com/${req.params.shortcode}/stats`;
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
return response.json();
}).then((data) => {
res.send(data);
});
});
server.listen(3000);