Skip to content

Commit c1d91c6

Browse files
Jayson SanonJayson Sanon
Jayson Sanon
authored and
Jayson Sanon
committed
fixed fetching data with cloudwatch sdk
1 parent 4cc8fe7 commit c1d91c6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

backend/cloudwatch.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import {
66
import { fromIni } from '@aws-sdk/credential-providers';
77
const region = 'us-east-1';
88

9+
// let log = {
10+
// metric: ['NetworkIn'],
11+
// data: [],
12+
// graph: ['bar'],
13+
// };
14+
915
async function MixedMetrix(metricMap) {
1016
const client = new CloudWatchClient({
1117
region,
@@ -86,4 +92,6 @@ async function MixedMetrix(metricMap) {
8692
}
8793
}
8894

95+
//MixedMetrix(log);
96+
8997
export default MixedMetrix;

backend/fetch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export async function AWSdata(graphs) {
88
body: JSON.stringify(graphs),
99
});
1010

11+
if (!res.ok) {
12+
throw new Error('Network response was not ok');
13+
}
14+
1115
let data = await res.json();
1216

1317
return data;

backend/serve.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ const port = 81;
66

77
const app = express();
88

9-
app.use(cors());
9+
app.use(
10+
cors({
11+
origin: true,
12+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
13+
allowedHeaders: ['Content-Type'],
14+
credentials: true,
15+
preflightContinue: false,
16+
})
17+
);
1018
app.use(express.json());
1119
app.use(express.urlencoded({ extended: true }));
1220

@@ -18,7 +26,13 @@ app.get('/random', async (req, res) => {
1826
app.post('/data', async (req, res) => {
1927
const { graph, metric, data } = req.body;
2028
let result = await MixedMetrix({ graph, metric, data });
21-
return res.status(200).json({result});
29+
return res.status(200).json({ result });
30+
});
31+
32+
app.options('/data', async (req, res) => {
33+
const { graph, metric, data } = req.body;
34+
let result = await MixedMetrix({ graph, metric, data });
35+
return res.status(200).json({ result });
2236
});
2337

2438
app.use((req, res) => res.status(404).send('No Data'));

0 commit comments

Comments
 (0)