-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
53 lines (43 loc) · 1.41 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
45
46
47
48
49
50
51
52
53
require('dotenv').config();
const express = require('express');
// const { createAssetJob } = require('./queue');
require('./sync-assets-queue');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const app = express();
const port = process.env.PORT || 3000;
app.use(cookieParser());
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// List of allowed origins
const allowedOrigins = [
'http://localhost:8100',
'http://localhost:5173',
process.env.UI_ENDPOINT
];
// CORS configuration function
const corsOptions = {
origin: (origin, callback) => {
if (allowedOrigins.includes(origin) || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true // Allow credentials (cookies, authorization headers, etc.)
};
app.use(cors(corsOptions));
app.set('trust proxy', 1);
// Routes
const dashboardRoutes = require('./routes/dashboard');
const knowledgeBankRoutes = require('./routes/knowledgeBank');
const notificationRoutes = require('./routes/notifications');
app.use('/dashboard', dashboardRoutes);
app.use('/knowledge-bank', knowledgeBankRoutes);
app.use('/notifications', notificationRoutes);
const server = app.listen(port, () => {
console.log(`Edge node backend running on port ${port}`);
});
server.setTimeout(120000);
module.exports = app;