-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (48 loc) · 1.49 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var path = require("path");
var flash = require('express-flash-2');
var express = require("express");
var app = express();
var cookieParser = require('cookie-parser')
var session = require('express-session');
var cors = require('cors');
require("dotenv").config();
app.use(cookieParser());
app.use(session({ secret: "Secret", saveUninitialized: false, resave: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(flash());
app.use(cors({
origin: '*'
}))
let PORT = process.env.PORT;
app.set('view engine', '.ejs');
app.listen(PORT);
console.log("Running at Port:" + PORT);
var config = {
method: 'get',
url: 'https://jsonplaceholder.typicode.com/users'
};
const axios = require('axios');
let alumst = async (req, res) => {
try {
const response1 = await axios.get(`https://studests.herokuapp.com/apistudents/getstudents`);
const response2 = await axios.get(`https://servnotas.herokuapp.com/apinotas/getnotas`);
const dat1 = response1.data;
const dat2 = response2.data;
len = dat1.length < dat2.length ? dat1.length : dat2.length;
data = []
for (let index = 0; index < len; index++) {
aux = {
"nombre": dat1[index].nombre,
"nombrecurso": dat2[index].nombrecurso,
"promedio": dat2[index].califi,
}
data = [...data, aux]
}
res.send(data)
} catch (error) {
// In the event of an error, return a 500 error and the error message
console.error(error);
res.send(error);
}
}
app.get('/alums', alumst);