-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
117 lines (78 loc) · 4 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// ────────────────────────────────────────────────────────────────────── I ──────────
// :::::: A P P E N T R Y P O I N T : : : : : : : :
// ────────────────────────────────────────────────────────────────────────────────
//
/**********************************************************************************
*
* This is the Frontal Application Layer that interacts with http request with
* the help of back-end
* conponents, database schemas and route
*
***********************************************************************************/
//
// ─── IMPORTS ────────────────────────────────────────────────────────────────────
//
//
// ─── DEPENDENCIES ───────────────────────────────────────────────────────────────
//
const mongoose =
require("mongoose")
const express =
require("express");
const bodyParser =
require("body-parser");
const appCommons =
require("./app.commons");
//
// ─── CUSTOM DEPENDENCIES ────────────────────────────────────────────────────────
//
const userRoutes =
require('./routes/user-routes')
const guestRoutes =
require('./routes/guest-routes')
const garbageRoutes =
require('./routes/garbage-routes')
const errorHandler =
require('./middleware/error/error-handler.mware')
//
// ─── CONSTANTS ──────────────────────────────────────────────────────────────────
//
const MONGODB_CONNECTION_URI =
process.env.MONGODB_CONNECTION_URI;
const app =
express();
//
// ─── GENERAL MIDDLEWARES ────────────────────────────────────────────────────────
//
app.use( bodyParser.json() )
app.use(( req, res, next ) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')
if(req.method === 'OPTIONS'){
return res.sendStatus(200)
}
next()
})
//
// ─── ROUTES MIDDLEWARES ─────────────────────────────────────────────────────────
//
app.use(userRoutes)
app.use(garbageRoutes)
app.use(guestRoutes)
//
// ─── ERROR HANDLING MIDDLEWARE ──────────────────────────────────────────────────
//
app.use(errorHandler)
//
// ─── DATA CONNNECTION AND HTTP SERVER LISTENING @ PORT 3020 ──────────────────────────────────
//
// app.listen(3020);
mongoose
.connect(MONGODB_CONNECTION_URI)
.then(() => {
console.log("working fyn")
app.listen(process.env.PORT || 3030);
})
.catch((error ) => { console.log("something went wrong")});