-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (37 loc) · 1.06 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
40
41
42
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var dotenv = require("dotenv");
dotenv.config();
var cors = require("cors");
var indexRouter = require("./routes/index");
var usersRouter = require("./routes/users");
const mongoose = require("mongoose");
var app = express();
app.use(cookieParser());
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, "public")));
var corsOptions = {
origin: [
"https://finalproject-yscx.onrender.com",
"http://localhost:3000",
"https://bounce-rouge.vercel.app",
],
optionsSuccessStatus: 200,
};
app.use(cors(corsOptions));
app.use("/", indexRouter);
app.use("/users", usersRouter);
async function connectToDatabase() {
try {
await mongoose.connect(process.env.MONGO_URI);
console.log("Connected to Database!");
} catch (error) {
console.error("MongoDB connection error:", error);
}
}
connectToDatabase();
module.exports = app;