-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (43 loc) · 1.11 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import express from "express";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import cors from "cors";
import helmet from "helmet";
import usersRouter from "./routes/users.js";
import carsRouter from "./routes/cars.js";
import bikesRouter from "./routes/bikes.js";
dotenv.config();
const app = express();
const PORT = process.env.PORT || 5000;
let database = process.env.MONGO_URI
if (process.env.NODE_ENV === "testing") {
database = process.env.MONGO_URI_TEST;
}
mongoose
.connect(database, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log("Database connection established");
})
.catch((err) => {
console.error(`ERROR: ${err}`);
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
cors({
origin: process.env.FRONTEND_URL,
})
);
app.use(helmet());
app.use("/users", usersRouter);
app.use("/cars", carsRouter);
app.use("/bikes", bikesRouter);
app.listen(PORT, () => {
console.log(`Listening on PORT: ${PORT}`);
});
export default app;