-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (32 loc) · 1.05 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
import express from "express";
import cors from "cors";
import bodyParser from "body-parser";
import passport from "passport";
import userRoutes from "./routes/user.routes.js";
import refferalRoutes from "./routes/refferal.routes.js";
import { fileURLToPath } from "url";
import path from "path";
import "./config/db.js";
import "./middleware/auth.middleware.js";
const app = express();
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.use(bodyParser.json());
app.use(passport.initialize());
// Static files
const __dirname = path.dirname(fileURLToPath(import.meta.url));
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.use("/api/users", userRoutes);
app.use("/api/referrals", refferalRoutes);
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
})
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "public", "unavailable.html"));
})
const PORT = process.env.PORT || 5001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});