Skip to content

Commit

Permalink
server: fix mail not sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal authored Jul 18, 2024
2 parents 28df664 + 9683047 commit ff95f20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
8 changes: 1 addition & 7 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,7 @@ exports.recoverAccount = async function (fastify, request, reply) {
message: `Activation link sent to your email${username ? (': ' + user[0].email) : ''}`
});
})
.catch(errors => {
reply.status(400).send({
success: false,
message: 'Something went wrong',
errors
});
});
.catch(errors => { throw new ErrorHandler(400, false, 'Something went wrong') });
} catch (err) {
return catchError(reply, err);
}
Expand Down
34 changes: 4 additions & 30 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,6 @@ fastify.decorate('upload', upload)

fastify.decorate('mysql', require('./db'))

const logs = [];
fastify.addHook('onRequest', async (request, reply) => {
request.logEntry = {
method: request.method,
url: request.url,
headers: request.headers,
body: request.body,
timestamp: new Date().toISOString()
};
});
fastify.addHook('onSend', async (request, reply, payload) => {
const responseLog = {
statusCode: reply.statusCode,
headers: reply.getHeaders(),
payload: payload,
timestamp: new Date().toISOString()
};
logs.push({ request: request.logEntry, response: responseLog });

if (logs.length > 1000) logs.shift();
});
fastify.get('/logs', (request, reply) => {
reply.send(logs);
});

fastify.register(require('@fastify/oauth2'), {
name: 'googleOAuth2',
scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
Expand All @@ -67,18 +42,17 @@ fastify.register(require('fastify-mailer'), {
defaults: { from: `${process.env.EMAIL_USER} <${process.env.EMAIL_ADDRESS}>` },
transport: {
host: 'smtp.gmail.com',
port: 587,
secure: false,
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_ADDRESS,
pass: process.env.EMAIL_PASSWORD
},
tls: {
rejectUnauthorized: true
}
}
})

fastify.get('/api', (request, reply) => reply.code(200).send('DebateMe server running...'))

fastify.register(require('./routes/auth'), { prefix: '/api/auth' })

fastify.setNotFoundHandler((request, reply) => {
Expand Down
17 changes: 17 additions & 0 deletions server/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"BRANCH": "vercel"
},
"builds": [
{
"src": "./server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.js"
}
]
}

0 comments on commit ff95f20

Please sign in to comment.