-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.21 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
const express = require("express");
const cors = require("cors");
const { connection } = require("./config/db");
const Routes = require("./routes/router");
const session = require("express-session");
const cookieParser = require("cookie-parser");
require("dotenv").config();
const app = express();
const PORT = 3000;
const corsOptions = {
origin: "https://ecommerce-sarung.vercel.app", // Atur origin sesuai domain Next.js
credentials: true, // Izinkan pengiriman cookie
};
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set("trust proxy", 1);
app.use(
session({
secret: process.env.secret_session,
resave: false,
saveUninitialized: true,
cookie: {
secure: true,
httpOnly: true,
sameSite: "none",
},
})
);
app.get("/", function (req, res) {
res.send("selamat Datang di API Backend Server ecommerce");
});
// routes /api
app.use("/api", Routes.routes);
app.use("/api/auth", Routes.routesAuth);
app.use("/api/cart", Routes.routesAddCart);
app.use("/api/revenue", Routes.routesRevenue);
app.listen(PORT, function (err) {
if (err) console.log(err);
console.log("Server listning on PORT", PORT);
});