-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (40 loc) · 1.16 KB
/
app.js
File metadata and controls
49 lines (40 loc) · 1.16 KB
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
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const cron = require('node-cron');
const axios = require('axios');
const { updateRatingsAndScores, fetchData } = require('./scrap');
const app = express();
app.use(express.json());
app.use(cors());
app.use(morgan('dev'));
app.use('/api', require('./routers/micpRouter'));
app.get('/', (req, res) => {
res.status(200).json({
status: true,
msg: 'working...',
});
});
// croning the updateRatingsAndScores function every 24 hours
cron.schedule('0 0 * * *', async () => {
await fetchData();
await updateRatingsAndScores();
console.log('updated scores and ratings');
});
// to ping the render server to stay alive
cron.schedule('*/10 * * * *', async () => {
await axios.get('https://micp-backend.onrender.com/').then((response) => {
console.log(response.status, response.statusText);
}).catch((error) => {
console.log(error);
});
});
// to handled unregister endpoint
app.all('*', (req, res) => {
res.status(404).json({
status: false,
msg: `Can't find ${req.originalUrl} on this server!`,
});
});
// fetchData();
module.exports = app;