-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.29 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 app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const authController = require("./controllers/auth_controller");
const dburitemp="mongodb+srv://vicky:vicky@cluster0.syoeipa.mongodb.net/CATOFF?retryWrites=true&w=majority"
dotenv.config();
// CORS configuration
app.use(
cors({
origin: "http://192.168.1.8:8081", // Update with your production domain
})
);
// Serving static files
app.use("/public", express.static(__dirname + "/public"));
// Body parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({ extended: false }));
// Routes
app.get("/", authController.start);
app.use("/api", require("./routes"));
// MongoDB connection
const dbURI = process.env.MONGO_URL;
mongoose
.connect(dburitemp, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to MongoDB");
// Start the server
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
})
.catch((error) => {
console.error("Error connecting to MongoDB:", error.message);
});