@@ -10,25 +10,34 @@ export default async (req, res) => {
10
10
}
11
11
12
12
try {
13
- const { name, email : emailAddress , subject, message, subscribe, gReCaptchaToken } = req . body ;
13
+ const {
14
+ name,
15
+ email : emailAddress ,
16
+ subject,
17
+ message,
18
+ subscribe,
19
+ gReCaptchaToken,
20
+ } = req . body ;
14
21
15
22
// verify recaptcha token
16
- const reCaptchaValidation = await ( await fetch ( 'https://www.google.com/recaptcha/api/siteverify' , {
17
- method : 'POST' ,
18
- headers : {
19
- 'Content-Type' : 'application/x-www-form-urlencoded'
20
- } ,
21
- body : `secret=${ process . env . RECAPTCHA_SECRET_KEY } &response=${ req . body . gReCaptchaToken } `
22
- } ) ) . json ( ) ;
23
+ const reCaptchaValidation = await (
24
+ await fetch ( 'https://www.google.com/recaptcha/api/siteverify' , {
25
+ method : 'POST' ,
26
+ headers : {
27
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
28
+ } ,
29
+ body : `secret=${ process . env . RECAPTCHA_SECRET_KEY } &response=${ req . body . gReCaptchaToken } ` ,
30
+ } )
31
+ ) . json ( ) ;
23
32
24
33
if ( reCaptchaValidation . success ) {
25
- // TODO: change the emails to '[email protected] ' before PR
34
+ // TODO: change the emails to '[email protected] ' before PR
26
35
// receiverEmail: The email will be sent here
27
- const receiverEmail = process . env . SENDGRID_DEV_EMAIL ;
36
+ const receiverEmail = '[email protected] ' ;
28
37
// sendgridEmail: This is the email verfied by sendgrid
29
38
// the email will appear to be sent from this email
30
39
// If a non verified email is used, we get a 403 error
31
- const sendgridEmail = process . env . SENDGRID_DEV_EMAIL ;
40
+ const sendgridEmail = '[email protected] ' ;
32
41
33
42
const emailContent = `
34
43
<b>Name:</b> ${ name } <br/>
@@ -42,33 +51,32 @@ export default async (req, res) => {
42
51
to : receiverEmail ,
43
52
from : {
44
53
email : sendgridEmail ,
45
- name : 'Web Dev Path'
54
+ name : 'Web Dev Path' ,
46
55
} ,
47
56
replyTo : {
48
57
email : emailAddress ,
49
- name
58
+ name,
50
59
} ,
51
60
subject : `New message from ${ name } via webdevpath.co 'Contact Us' Form` ,
52
61
content : [
53
62
{
54
- ' type' : 'text/html' ,
55
- ' value' : emailContent
56
- }
57
- ]
63
+ type : 'text/html' ,
64
+ value : emailContent ,
65
+ } ,
66
+ ] ,
58
67
} ;
59
68
await sendgrid . send ( email ) ;
60
69
res . status ( 200 ) . json ( { status : 'OK' } ) ;
61
- } else {
70
+ } else {
62
71
return res . status ( 422 ) . json ( {
63
- status :'error' ,
64
- message : 'Invalid ReCaptcha'
65
- } )
72
+ status : 'error' ,
73
+ message : 'Invalid ReCaptcha' ,
74
+ } ) ;
66
75
}
67
76
} catch ( e ) {
68
77
return res . status ( 500 ) . json ( {
69
78
status : 'error' ,
70
- message : `Error: ${ e . message } `
79
+ message : `Error: ${ e . message } ` ,
71
80
} ) ;
72
81
}
73
-
74
- }
82
+ } ;
0 commit comments