-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.mjs
More file actions
53 lines (39 loc) · 1.24 KB
/
index.mjs
File metadata and controls
53 lines (39 loc) · 1.24 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
51
52
53
import express from "express";
import cors from "cors";
import path from "path";
import { fileURLToPath } from "url";
import compression from "compression";
import setupSwagger from "./swagger/swagger.mjs";
import apiRouter from "./routes/api.mjs";
const app = express();
const port = 3000;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(compression());
app.use(express.static(path.join(__dirname, "public")));
/* app.use(cors()); */
const corsOptions = {
origin: [
"https://ucuzasistem.com",
"https://www.ucuzasistem.com",
"https://ucuzasistem.up.railway.app",
],
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
};
app.use(cors(corsOptions));
app.use(express.json());
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "main.html"));
});
app.get("/anasayfa", (req, res) => {
res.sendFile(path.join(__dirname, "public", "main.html"));
});
app.use("/api", apiRouter);
setupSwagger(app);
app.use((req, res, next) => {
res.status(404).sendFile(path.join(__dirname, "public", "404.html"));
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});