-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
43 lines (34 loc) · 1.03 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
43
const PORT = process.env.PORT || 8000;
require('dotenv').config()
const axios = require('axios');
const cors = require('cors');
const express = require('express');
const app = express();
const path = require("path");
app.use(cors());
app.use(express.static(path.join(__dirname, "build")));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/news', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/api/news', (req, res) => {
var options = {
method: 'GET',
url: 'https://crypto-news-live3.p.rapidapi.com/news',
headers: {
'x-rapidapi-host': 'crypto-news-live3.p.rapidapi.com',
'x-rapidapi-key': process.env.REACT_APP_RAPID_API_KEY
}
};
axios.request(options).then((response) => {
res.json(response.data)
})
.catch((error) => {
console.error(error);
});
})
app.listen(PORT, ()=>{
console.log(`Server running at http://localhost:${PORT}`)
})