-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
40 lines (34 loc) · 975 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
36
37
38
39
40
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const { getNotices, getNoticeContent } = require("./notices");
const app = express();
app.use(bodyParser.json());
app.use(cors());
const port = 3000;
app.get("/", (req, res) => res.send("Hello World!"));
app.get("/notices/:category?", async (req, res) => {
const baseUrl = "https://pu.edu.np/";
const url = req.params.category
? baseUrl + `noticetype/${req.params.category}`
: baseUrl + "notice";
console.log(url);
getNotices(url, (notices) => {
res.json({
timeStamp: Date.now(),
notices: notices,
});
});
});
app.post("/notice/", async (req, res) => {
const { body } = req;
const { url } = body;
getNoticeContent(url, (notice) => {
// console.log(notice);
res.json({
timeStamp: Date.now(),
notice: notice,
});
});
});
app.listen(port, () => console.log(`App listening on port ${port}!`));