/
backend.js
39 lines (30 loc) · 997 Bytes
/
backend.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
const express = require('express');
const request = require('request');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
const path = require('path');
let url = "https://api.ibb.gov.tr/ispark/Park"
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/api/data', (req, res) => {
data = [];
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
for (var i in body) {
data.push(body[i])
}
}
res.json(data);
})
})
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'frontend/build')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'frontend/build', 'index.html'));
});
}
app.listen(port, () => console.log(`Listening on port ${port}`));