1
- const express = require ( ' express' )
2
- const cors = require ( ' cors' )
3
- const bodyParser = require ( ' body-parser' )
1
+ const express = require ( " express" ) ;
2
+ const cors = require ( " cors" ) ;
3
+ const bodyParser = require ( " body-parser" ) ;
4
4
const app = express ( ) ;
5
+ require ( "dotenv" ) . config ( ) ;
5
6
6
7
// user verification
7
- const verifyToken = require ( ' ./ValidateUser/validateuser' )
8
+ const verifyToken = require ( " ./ValidateUser/validateuser" ) ;
8
9
9
10
// google photos
10
- const { getAlbum } = require ( ' ./GooglePhotos/googlePhotos' )
11
+ const { getAlbum } = require ( " ./GooglePhotos/googlePhotos" ) ;
11
12
12
13
// mail
13
- const transporter = require ( ' ./Mailer/transporter' )
14
- const sendEmail = require ( ' ./Mailer/mail' )
14
+ const transporter = require ( " ./Mailer/transporter" ) ;
15
+ const sendEmail = require ( " ./Mailer/mail" ) ;
15
16
16
17
// constants
17
- const { EMAIL , EMAILTO , ALBUMID } = require ( ' ./constants' )
18
+ const { EMAIL , EMAILTO , ALBUMID } = require ( " ./constants" ) ;
18
19
19
20
// middlewares
20
21
app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
21
- app . use ( bodyParser . json ( ) )
22
- app . use ( cors ( ) )
22
+ app . use ( bodyParser . json ( ) ) ;
23
+ app . use ( cors ( ) ) ;
23
24
24
25
app . use ( express . static ( "public" ) ) ;
25
26
26
27
/**
27
28
* To change email id (to be used for sending emails)
28
- *
29
+ *
29
30
* 1. Go to account setting of your GMAIL account.
30
31
* 2. Then go to 'allow less secure apps..'.
31
32
* 3. Generate a new password and use that here to allow nodemailer to logging in your gmail account, skipping 2 step verification step.
32
- *
33
+ *
33
34
* Reference:
34
35
* https://stackoverflow.com/questions/26196467/sending-email-via-node-js-using-nodemailer-is-not-working
35
- *
36
+ *
36
37
*/
37
38
38
-
39
39
/**
40
40
* this endpoint is for sending user's credentials when a new account is created from admin panel.
41
41
*/
42
42
43
- app . post ( "/sendMail" , verifyToken , async ( req , res , next ) => {
44
-
45
- let mailOptions = {
46
- from : EMAIL ,
47
- to : req . body . email || EMAIL ,
48
- subject : 'Technocrats Member Profile Credentials' ,
49
- html : `
43
+ app . post ( "/sendMail" , verifyToken , async ( req , res , next ) => {
44
+ let mailOptions = {
45
+ from : EMAIL ,
46
+ to : req . body . email || EMAIL ,
47
+ subject : "Technocrats Member Profile Credentials" ,
48
+ html : `
50
49
<h1>Welcome to Technocrats Robotics</h1>
51
50
<p>Click on the <strong>Member Login</strong> button at the bottom footer of the web app.</p>
52
51
<p><span style="color: #0000ff;">Following are your credentials to customize your profile on the web app:<br /> <span style="color: #ff0000;"><strong>Username:</strong> ${ req . body . data . username } </span><br /><span style="color: #ff0000;"><strong>Password:</strong> ${ req . body . data . password } <br /></span>Whosoever holds these credentials, if he be worthy, shall possess the power of a Member.</span></p>
@@ -55,73 +54,70 @@ app.post("/sendMail", verifyToken ,async (req, res, next) => {
55
54
<blockquote>
56
55
<p><strong>This is only a foretaste of what is to come, and only the shadow of what is going to be. <em>~ Alan Turing</em></strong></p>
57
56
</blockquote>
58
- `
59
- } ;
60
-
61
- let response = await sendEmail ( transporter , mailOptions , next )
57
+ ` ,
58
+ } ;
62
59
63
- if ( response )
64
- res . status ( 200 ) . send ( { message : "Sent" } ) ;
65
- } )
60
+ let response = await sendEmail ( transporter , mailOptions , next ) ;
66
61
62
+ if ( response ) res . status ( 200 ) . send ( { message : "Sent" } ) ;
63
+ } ) ;
67
64
68
65
/**
69
- * endpoint to send feedback submitted by user in Contact Us form to TCR's official mail id
66
+ * endpoint to send feedback submitted by user in Contact Us form to TCR's official mail id
70
67
*/
71
- app . post ( "/sendFeedback" , verifyToken , async ( req , res , next ) => {
72
-
73
- let mailOptions = {
74
- from : EMAIL ,
75
- to : EMAILTO ,
76
- subject : 'Got a Feedback !!' ,
77
- html : `
68
+ app . post ( "/sendFeedback" , verifyToken , async ( req , res , next ) => {
69
+ let mailOptions = {
70
+ from : EMAIL ,
71
+ to : EMAILTO ,
72
+ subject : "Got a Feedback !!" ,
73
+ html : `
78
74
<h1><u>Feedback</u></h1>
79
75
<p><b><u>Name:</u></b> ${ req . body . data . name } </p>
80
76
<p><b><u>Email:</u></b> ${ req . body . data . email } </p>
81
77
<p><b><u>Contact:</u></b> ${ req . body . data . contact } </p>
82
78
<p><b><u>Message:</u></b> ${ req . body . data . message } </p>
83
- `
84
- } ;
85
-
86
- const response = await sendEmail ( transporter , mailOptions , next )
79
+ ` ,
80
+ } ;
87
81
88
- if ( response )
89
- res . status ( 200 ) . send ( { message : "Sent" } ) ;
90
- } )
82
+ try {
83
+ const response = await sendEmail ( transporter , mailOptions , next ) ;
91
84
85
+ if ( response ) res . status ( 200 ) . send ( { message : "Sent" } ) ;
86
+ } catch ( err ) {
87
+ next ( err ) ;
88
+ }
89
+ } ) ;
92
90
93
91
/**
94
92
* get the album id from google photos and pass it in the function getAlbum(<id>)
95
- *
93
+ *
96
94
*/
97
95
98
- app . get ( "/gallery" , verifyToken , async ( req , res , next ) => {
99
- const result = await getAlbum ( ALBUMID )
100
- res . json ( result )
101
- } )
96
+ app . get ( "/gallery" , verifyToken , async ( req , res , next ) => {
97
+ const result = await getAlbum ( ALBUMID ) ;
98
+ res . json ( result ) ;
99
+ } ) ;
102
100
103
101
/*
104
102
* information
105
103
*/
106
104
app . get ( "/" , ( req , res , next ) => {
107
- res . sendFile ( __dirname + "/" + "Information/information.html" )
108
- } )
105
+ res . sendFile ( __dirname + "/" + "Information/information.html" ) ;
106
+ } ) ;
109
107
110
108
// error handler
111
109
app . use ( ( err , req , res , next ) => {
112
- res . status ( err . status || 500 )
113
- res . send ( {
114
- error : {
115
- status : err . status || 500 ,
116
- message : err . message
117
- }
118
- } )
119
- } )
120
-
110
+ res . status ( err . status || 500 ) ;
111
+ res . send ( {
112
+ error : {
113
+ status : err . status || 500 ,
114
+ message : err . message ,
115
+ } ,
116
+ } ) ;
117
+ } ) ;
121
118
122
119
var port = process . env . PORT || 5000 ;
123
120
124
-
125
121
app . listen ( port , function ( ) {
126
- console . log ( ' Express server listening on port ' + port ) ;
122
+ console . log ( " Express server listening on port " + port ) ;
127
123
} ) ;
0 commit comments