From 5b2efe7ed498f370fb6692d4ac4c6ccf91063fa5 Mon Sep 17 00:00:00 2001 From: Ujjwal Saini Date: Mon, 14 Oct 2024 18:37:00 +0530 Subject: [PATCH] Deploy to Prod --- Backend/.gitignore | 2 ++ Backend/package-lock.json | 13 +++++++++++++ Backend/package.json | 1 + Backend/server.js | 8 ++++++-- Backend/vercel.json | 20 ++++++++++++++------ src/pages/SweetEmail.js | 5 +++-- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 Backend/.gitignore diff --git a/Backend/.gitignore b/Backend/.gitignore new file mode 100644 index 0000000..83baf96 --- /dev/null +++ b/Backend/.gitignore @@ -0,0 +1,2 @@ +.vercel +.env \ No newline at end of file diff --git a/Backend/package-lock.json b/Backend/package-lock.json index 2d6446d..9c414da 100644 --- a/Backend/package-lock.json +++ b/Backend/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "body-parser": "^1.20.3", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.21.1", "nodemailer": "^6.9.15" } @@ -168,6 +169,18 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/Backend/package.json b/Backend/package.json index 60dd51f..520f305 100644 --- a/Backend/package.json +++ b/Backend/package.json @@ -12,6 +12,7 @@ "dependencies": { "body-parser": "^1.20.3", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.21.1", "nodemailer": "^6.9.15" } diff --git a/Backend/server.js b/Backend/server.js index f56458b..ba0aa53 100644 --- a/Backend/server.js +++ b/Backend/server.js @@ -2,6 +2,7 @@ const express = require('express'); const nodemailer = require('nodemailer'); const cors = require('cors'); const bodyParser = require('body-parser'); +require("dotenv").config() const app = express(); const PORT = 5000; // You can change the port if needed @@ -13,8 +14,8 @@ app.use(bodyParser.json()); const transporter = nodemailer.createTransport({ service: 'gmail', // You can use another service like SendGrid or SMTP auth: { - user: 'saini.ujjwals007@gmail.com', - pass: 'pnot bnpc cfwp wnyx', + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASS, }, }); @@ -59,6 +60,9 @@ app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); }); +export default app; + + // TOdo: Basic Code with only post request not having Get Request // const express = require('express'); // const nodemailer = require('nodemailer'); diff --git a/Backend/vercel.json b/Backend/vercel.json index f6875a8..f56ea35 100644 --- a/Backend/vercel.json +++ b/Backend/vercel.json @@ -1,7 +1,15 @@ { - "version": 2, - "builds": [ - { "src": "api/**/*.js", "use": "@vercel/node" } - ] - } - \ No newline at end of file + "version": 2, + "builds": [ + { + "src": "server.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "/server.js" + } + ] +} \ No newline at end of file diff --git a/src/pages/SweetEmail.js b/src/pages/SweetEmail.js index 5381203..9b30aef 100644 --- a/src/pages/SweetEmail.js +++ b/src/pages/SweetEmail.js @@ -15,8 +15,9 @@ const EmailPusher = () => { if (email) { // Make POST request to send email - const response = await fetch('http://localhost:5000/send-email', { // Update the URL if needed - method: 'POST', + // const response = await fetch('http://localhost:5000/send-email', { + const response = await fetch('https://vedic-vani-backend.vercel.app/send-email', { + method: 'POST', headers: { 'Content-Type': 'application/json', },