-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (60 loc) · 2.46 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require("express-async-errors");
const winston = require("winston");
require("winston-mongodb");
const config = require("config");
const error = require("./middlewares/error");
const Joi = require("joi");
Joi.objectId = require("joi-objectid")(Joi);
const mongoose = require("mongoose");
const express = require("express");
const app = express();
var cors = require("cors");
app.use(cors());
const genres = require("./routes/genres");
const customers = require("./routes/customers");
const movies = require("./routes/movies");
const rentals = require("./routes/rentals");
const users = require("./routes/users");
const customer_movies = require("./routes/customer_movies");
const auth = require("./routes/auth");
const helmet = require("helmet");
const compression = require("compression");
//winston.add(new winston.transports.File(), { filename: "logfile.log" });
winston.add(
new winston.transports.File({ filename: "logfile.log", level: "error" })
);
winston.add(
new winston.transports.MongoDB({
//db: "mongodb://localhost:/vidly",
db: "mongodb://omg:[email protected]:27017,cluster0-shard-00-01.yfmpt.mongodb.net:27017,cluster0-shard-00-02.yfmpt.mongodb.net:27017/vidly?ssl=true&replicaSet=atlas-3l3xds-shard-0&authSource=admin&retryWrites=true&w=majority",
})
);
if (!config.get("jwtPrivateKey")) {
console.error("Fatal Error: jwtPrivateKey is not defined");
process.exit(1);
}
// .connect("mongodb+srv://omg9800:[email protected]/vidly")
// .connect("mongodb://localhost:/vidly")
// .connect("mongodb://localhost:/vidly")
mongoose
.connect(
"mongodb://omg:[email protected]:27017,cluster0-shard-00-01.yfmpt.mongodb.net:27017,cluster0-shard-00-02.yfmpt.mongodb.net:27017/vidly?ssl=true&replicaSet=atlas-3l3xds-shard-0&authSource=admin&retryWrites=true&w=majority"
)
.then(() => console.log("Connected to mongodb..."))
.catch((err) => console.log("Could not connect to mongodb"));
app.use(express.json());
app.use("/api/genres", genres);
app.use("/api/customers", customers);
app.use("/api/movies", movies);
app.use("/api/rentals", rentals);
app.use("/api/users", users);
app.use("/api/auth", auth);
app.use("/api/customer_movies", customer_movies);
app.use(error);
app.use(helmet());
app.use(compression());
const port = process.env.PORT || 3000;
if (process.env.NODE_ENV === "production") {
app.use(express.static("vidly/build"));
}
app.listen(port, () => console.log(`listening on port ${port}...`));