-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
52 lines (42 loc) · 1.18 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
const express = require("express");
const cors = require("cors");
const indexRouter = require("./routes");
const apiRouter = require("./routes/api");
const config = require("./config");
const mongoose = require("mongoose");
const swaggerUi = require("swagger-ui-express");
const swaggerDocument = require("./Bloggify-swagger.json");
const app = express();
const PORT = config.PORT;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Swagger UI API Documentation
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// to allow cross origin requests
app.use(cors());
// connection to databse
mongoose
.connect(config.mongoUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("CONNECTED TO %s", config.mongoUrl);
})
.catch((error) => {
console.log("DATABASE CONNECTION ERROR: ", error.message);
process.exit(1);
});
// router for the api
app.use("/", indexRouter);
app.use("/api", apiRouter);
app.listen(PORT, (req, res) => {
console.log(`Server up and running on ${PORT}`);
});
// * TODOS
/**
*
* * Notification with Twillio/Firebase - [optional]
* * Setup README with Routes for backend operations
*
*/