-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (47 loc) · 1.53 KB
/
server.js
File metadata and controls
53 lines (47 loc) · 1.53 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
50
51
52
53
const express = require('express');
const app = express();
const cors = require('cors');
const port = 3000;
const { Client } = require("@notionhq/client");
const utils = require('./utils');
require('dotenv').config();
const notionToken = process.env.NOTION_TOKEN;
const notion = new Client({ auth: notionToken });
const databaseId = process.env.DATABASE_ID;
// Middleware to parse JSON bodies
app.use(express.json());
app.use(cors());
// Serve static files from the "public" directory
app.use(express.static('public'));
// Define a route for the root URL
app.get('/', (req, res) => {
console.log(req.body);
});
// Define a route to handle log messages
app.post('/', async (req, res) => {
let msg = req.body;
console.log('Received message:', msg);
switch (msg.type) {
case "parseUrlAndContents": {
if (await utils.pageExists(msg.link) === false) {
await utils.createNewDatabaseEntry(msg);
}
break;
}
case 'verdict-accepted': {
await utils.updateStatus(msg.link);
break;
}
case 'handleVerdict': {
if(await utils.isQuestionSolved(msg.link) === false && msg.verdict === "Accepted") {
console.log("updating status");
await utils.updateStatus(msg.link);
}
}
}
res.json({ status: 'success' });
});
// Start the server
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});