-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (49 loc) · 1.58 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
57
58
59
60
61
62
63
64
65
66
67
68
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const compression = require("compression");
const helmet = require("helmet");
const connectDB = require("./config/db.config");
/**
* -------------- GENERAL SETUP ----------------
*/
// Gives us access to variables set in the .env file via `process.env.VARIABLE_NAME` syntax
require("dotenv").config();
// Connection to DB
connectDB();
// Create the Express application object
const app = express();
// Compress the HTTP response sent back to a client
app.use(compression()); //Compress all routes
// Use Helmet to protect against well known vulnerabilities
app.use(helmet());
// use Morgan dep in dev mode
app.use(morgan("dev"));
// Set up cors to allow us to accept requests from our client
// app.use(
// cors({
// origin: "http://localhost:3001", // <-- location of the react app were connecting to
// credentials: true,
// })
// );
app.use(cors());
// Parsers
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ extended: true }));
/**
* -------------- ROUTES ----------------
*/
require("./routes/auth.route")(app);
require("./routes/post.route")(app);
require("./routes/user.route")(app);
/**
* -------------- SERVER ----------------
*/
// Specify the PORT which will the server running on
const PORT = process.env.PORT || 3000;
// Disabling Powered by tag
app.disable("x-powered-by");
app.listen(PORT, () => {
console.log(`Server is running under port ${PORT}.`);
});
// ${process.env.NODE_ENV}