-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (42 loc) · 1.6 KB
/
app.js
File metadata and controls
50 lines (42 loc) · 1.6 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
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const app = express();
const router = require("./src/app/route/router");
const path = require("path");
const cors = require("cors");
const notFoundError = require("./src/error/not.found.error.js");
const globalErrorHandler = require("./src/error/global.error.js");
const webHookRouter = require('./src/app/modules/webhook/webhook.router.js');
app.use(
cors({
origin: [
'http://localhost:52643', // Local development (e.g., Flutter web running on this port)
'https://your-live-website-url.com', // Production admin panel hosted on Cloudflare Pages (HTTPS)
'', // Optional: HTTP version in case SSL is not enforced (usually not needed)
'', // Production/staging admin panel hosted on Vercel
],
credentials: true, // Allow cookies, authorization headers, or TLS client certificates in cross-origin requests
})
);
app.get("/", (req, res) => {
res.send("Server is Running");
});
app.use((req, res, next) => {
console.log(`Request URL: ${req.method} ${req.originalUrl}`);
console.log(`Request Body: ${req.body}`);
next();
});
app.use('/webhook', webHookRouter);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use("/api/uploads", express.static(path.join(__dirname, "uploads")));
app.use("/api", router);
// Global Error Handler
app.use(globalErrorHandler);
// Handle not found
app.use(notFoundError.hendle);
module.exports = app;