From c56574e4ef78d9eccd39967e2845c227221ce43f Mon Sep 17 00:00:00 2001 From: Shubham-Lal Date: Thu, 18 Jul 2024 13:02:43 +0530 Subject: [PATCH 1/2] server: add vercel.json --- server/server.js | 32 ++------------------------------ server/vercel.json | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 server/vercel.json diff --git a/server/server.js b/server/server.js index 81950a5..da7da3d 100644 --- a/server/server.js +++ b/server/server.js @@ -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', @@ -67,14 +42,11 @@ 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 } } }) diff --git a/server/vercel.json b/server/vercel.json new file mode 100644 index 0000000..04da709 --- /dev/null +++ b/server/vercel.json @@ -0,0 +1,17 @@ +{ + "env": { + "BRANCH": "vercel" + }, + "builds": [ + { + "src": "./server.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "server.js" + } + ] +} \ No newline at end of file From 96830472ee9756170e470f80a756521f5575ff44 Mon Sep 17 00:00:00 2001 From: Shubham-Lal Date: Thu, 18 Jul 2024 13:16:36 +0530 Subject: [PATCH 2/2] server: add test api --- server/controllers/auth.js | 8 +------- server/server.js | 2 ++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/server/controllers/auth.js b/server/controllers/auth.js index b61c2c0..5b0cc34 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -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); } diff --git a/server/server.js b/server/server.js index da7da3d..06742ce 100644 --- a/server/server.js +++ b/server/server.js @@ -51,6 +51,8 @@ fastify.register(require('fastify-mailer'), { } }) +fastify.get('/api', (request, reply) => reply.code(200).send('DebateMe server running...')) + fastify.register(require('./routes/auth'), { prefix: '/api/auth' }) fastify.setNotFoundHandler((request, reply) => {