-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (27 loc) · 1008 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
const { getAllFunds, getFundById, getHistoricalDataFundById } = require('./services/api/funds');
const path = require('path');
const express = require("express");
const PORT = process.env.PORT || 5000;
const app = express();
// Fazer o Node servir os arquivos para o cliente React
app.use(express.static(path.resolve(__dirname, './frontend/build')));
// Rotas da API
app.get('/api/funds', async (req, res) => {
let funds = await getAllFunds();
return res.json(funds);
});
app.get('/api/funds/:fundId', async (req, res) => {
let fund = await getFundById(req.params.fundId);
return res.json(fund);
});
app.get('/api/funds/historicaldata/:fundId', async (req, res) => {
let historicalData = await getHistoricalDataFundById(req.params.fundId);
return res.json(historicalData);
});
// Rotas gerenciadas pelo React
app.get('*', (req, res) => {
res.sendFile(path.resolve('./frontend/build', 'index.html'));
});
app.listen(PORT, () => {
console.log(`Servidor ativo na porta ${PORT}`);
});