-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (58 loc) · 1.8 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
62
63
64
65
66
import express from "express";
import { Client } from "@notionhq/client";
import 'dotenv/config';
import cors from "cors";
import helmet from "helmet"; // Import helmet properly
const app = express();
app.use(cors());
app.use(helmet());
app.use(
helmet.contentSecurityPolicy({
directives: {
"default-src": ["'self'"],
"connect-src": ["'self'", "'unsafe-inline'"],
"img-src": ["'self'", "data:"],
"style-src-elem": ["'self'", "data:"],
"script-src": ["'unsafe-inline'", "'self'"],
"object-src": ["'none'"],
},
})
);
const notion = new Client({
auth: process.env.NEXT_PUBLIC_NOTION_API_KEY, // Use environment variables
});
app.get('/execs-data', async (req, res) => {
try {
const response = await notion.databases.query({
database_id: process.env.NEXT_PUBLIC_NOTION_EXECUTIVES_DATABASE_ID,
});
const data = response.results.reverse().map(result => result.properties);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/events-data', async (req, res) => {
try {
const response = await notion.databases.query({
database_id: process.env.NEXT_PUBLIC_NOTION_EVENTS_DATABASE_ID,
});
const data = response.results.reverse().map(result => result.properties);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/resources-data', async (req, res) => {
try {
const response = await notion.databases.query({
database_id: process.env.NEXT_PUBLIC_NOTION_RESOURCES_DATABASE_ID,
});
const data = response.results.reverse().map(result => result.properties);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Export the app (for Vercel)
export default app;