-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (37 loc) · 1.29 KB
/
app.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
const express = require('express');
const path = require('path');
const { Console } = require('console');
const ejsMate = require('ejs-mate');
const fetch = require("node-fetch");
const app = express();
const url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?";
app.engine('ejs', ejsMate);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }))
app.use(express.static(path.join(__dirname, 'public')))
let availableSlots;
let getinfo = async function (pin, date) {
await fetch("https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?pincode=" + pin + "&date=" + date, {
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then((out) => {
const { sessions } = out;
availableSlots = sessions;
console.log(sessions);
})
.catch(err => console.error(err));
}
app.get('/form', async (req, res, next) => {
return res.render("form");
});
app.post("/track", async (req, res, next) => {
const { pin, date } = req.body;
await getinfo(pin, date);
res.render("slot", { availableSlots });
})
app.listen(3000, () => {
console.log('Serving port 3000');
})