-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (38 loc) · 1.09 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
require("dotenv").config();
require("./src/queues/queue.js");
require("./src/workers/worker.js");
const express = require("express");
const pipelineRoutes = require("./src/routes/pipelineRoutes.js");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const port = process.env.PORT || 5005;
const app = express();
const allowedOrigins = [
"http://localhost:8100",
"http://localhost:5173",
process.env.UI_ENDPOINT,
];
const corsOptions = {
origin: (origin, callback) => {
if (allowedOrigins.includes(origin) || !origin) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
credentials: true,
};
app.use(cookieParser());
app.use(cors(corsOptions));
app.set("trust proxy", 1);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use((req, res, next) => {
console.log(`Received request: ${req.method} ${req.url}`);
next();
});
app.use("/", pipelineRoutes);
const server = app.listen(port, () => {
console.log(`Edge Node knowledge mining running on port ${port}`);
});
module.exports = app;