-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
139 lines (116 loc) · 4.19 KB
/
Copy pathserver.js
File metadata and controls
139 lines (116 loc) · 4.19 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Impoting all required files <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const express = require('express')
const bodyParser = require('body-parser')
const controller = require('./controller/api-controller.js')
const validator = require('./validators/api-validator.js')
const constants = require('./constants')
const upload = require('express-fileupload')
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
const request = require('request')
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Using all required Middlewares <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const APP = express()
// For Uploading & viewing files
APP.use(upload())
APP.use('/upload', express.static('upload'))
// For parsing body data
APP.use(bodyParser.json())
APP.use(bodyParser.urlencoded({
extended: true
}))
// For Setting Template Engine & using static files
APP.set("template-engine", "ejs")
APP.use("/css", express.static('css'))
APP.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Routes & API calls <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/**
* @api <b>/login</b><br>
* Renders Login Page
*/
APP.get('/login', controller.loginPage)
/**
* @api <b>/signup-get</b><br>
* Renders Signup page
*/
APP.get('/signup', controller.signupPage)
/**
* @api <b>/getToken</b><br>
* Validates,verifies data & generates a token
* @param {string} fName - body
* @param {string} lName - body
* @param {string} email - body
* @param {string} password - body
* @param {number} phone_no - body
* @param {date} dob - body
*/
APP.post('/getToken', validator.validateLoginData, validator.verifyCredentials, controller.sendToken)
/**
* @api <b>/signup-post</b></br>
* validates data & stores to the database
* @param {string} email - body
* @param {string} password - body
*/
APP.post('/signup', validator.validateSignupData, controller.signupSuccess)
/**
* @api <b>/profile</b></br>
* sends back basic profile details of user
* @param {string} token - query
*/
APP.get('/profile', validator.verifyLogin, controller.showProfile)
/**
* @api <b>/uploadProfilePic</b></br>
* Validates image,token & stores to databse
* @param {string} token - query
* @param {file} image - body
*/
APP.post('/uploadProfilePic', validator.validateImage, validator.verifyLogin, controller.updatePicDB)
/**
* @api <b>/viewPic</b></br>
* Gives an image link where image is present
* @param {string} token - query
*/
APP.get('/viewPic', validator.verifyLogin, controller.showPicLink)
/**
* @api <b>/removePic</b></br>
* Delete pic from database
* @param {string} token - body
*/
APP.delete('/removePic', validator.verifyTokenBody, controller.removePic)
/**
* @api <b>/forgetPassword</b></br>
* Generates a 5-min token for reseting password
* @param {string} email - body
*/
APP.post('/forgetPassword', validator.validateFogetPwdData, controller.genTempToken)
/**
* @api <b>/resetPassword</b></br>
* Validates token & saves newly provided password
* @param {string} token - body
* @param {string} password - body
* @param {string} confirm_password - body
*/
APP.post('/resetPassword', validator.validateResetData, validator.verifyTokenBody, controller.resetPassword)
/**
* @api <b>/deleteAccount</b></br>
* Deletes account from database
* @param {string} token - body
*/
APP.delete('/deleteAccount', validator.verifyTokenBody, controller.delteAcc)
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Starting Server & Dataabse <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
APP.listen(3000, () => {
constants.CONNECTION.connect((err) => {
if (err) {
throw err
} else {
console.log("Congrats.. You're Connected!");
request('https://socket-chat-free.herokuapp.com',(err,response,body)=>{
if (err) {
console.log(err);
} else {
console.log(">>>>>>>>>>>>RESPONSE>>>>>>>>>>>>>>>>>>",response);
console.log(">>>>>>>>>>>>BODY>>>>>>>>>>>>>",body)
}
})
}
})
})