-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (29 loc) · 979 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
const express = require('express');
const app = express();
const port = 3001;
const fetch = require('node-fetch');
var randomNum = 0;
app.use(express.static('public'));
app.listen(port, () => {
console.log(`Example app listening: http://localhost:${port}`);
});
app.get('/hwdata', async(request, response) => {
const fetchApi = await fetch("http://localhost:3000/hw2023", {
method: 'GET',
headers: { }
});
randomNum = Math.floor(Math.random() * 400);
const hwdataResponse = await fetchApi.json();
//console.log(hwdataResponse[randomNum]);
response.json(hwdataResponse);
});
app.get('/hwimage', async(request, response) => {
const fetchApi = await fetch("http://localhost:3000/hw2023", {
method: 'GET',
headers: { }
});
//randomNum = Math.floor(Math.random() * 400);
const hwimageResponse = await fetchApi.json();
console.log(hwimageResponse[randomNum]);
response.json(hwimageResponse);
});