-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (28 loc) · 1.15 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
import "./env.js";
import express from "express";
import mongoose from "mongoose";
import cors from "cors";
import api from "./routes/index.js";
const app = express();
const { USER_NAME, PASSWORD, CLIENT_ORIGIN } = process.env;
const uri = `mongodb://${USER_NAME}:${PASSWORD}@cluster0-shard-00-00.kmfwq.mongodb.net:27017,cluster0-shard-00-01.kmfwq.mongodb.net:27017,cluster0-shard-00-02.kmfwq.mongodb.net:27017/ArtExhibit?ssl=true&replicaSet=atlas-a9v4hk-shard-0&authSource=admin&retryWrites=true&w=majority`;
//use the following uri when running local MongoDB server
// const uri = "mongodb://127.0.0.1:27017/ArtExhibit";
mongoose
.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("connected to DB"))
.catch((err) => console.log(err));
app.use(cors({ origin: `${CLIENT_ORIGIN || "http://localhost:3000"}` }));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.get("/", (req, res) => {
res.send("<h1>Welcome to ArtExhibit!</h1>");
});
app.use("/api", api);
const port = process.env.PORT || 5000;
app.listen(port, function () {
console.log("Server started on port: ", port);
});