From ad2ec4e0c1dae45bfd18241574f3ffbf5d72a04b Mon Sep 17 00:00:00 2001 From: Pranav Pore Date: Tue, 15 Oct 2024 22:04:24 +0530 Subject: [PATCH 1/2] setup backend for vercel deployment --- Backend/.env.example | 9 +-------- Backend/server.js | 26 ++++++++++++++------------ Backend/vercel.json | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 Backend/vercel.json diff --git a/Backend/.env.example b/Backend/.env.example index 3a2e97b..df86240 100644 --- a/Backend/.env.example +++ b/Backend/.env.example @@ -1,11 +1,4 @@ -# MongoDB Connection String DB_Url= - -# Port for your application PORT= - -# JWT Secret Key JWT_SECRET= - - - +NODE_ENV=development diff --git a/Backend/server.js b/Backend/server.js index 04bc673..09d4697 100644 --- a/Backend/server.js +++ b/Backend/server.js @@ -1,31 +1,33 @@ import express from "express"; import { PORT, mongoDBUrl } from "./config.js"; import cors from "cors"; -import mongoose from "mongoose"; -//import registrationRoutes from './api/routes/registerRoute.js'; -import patientRoutes from "./api/routes/PatientRoute.js"; +import mongoose from 'mongoose'; +import patientRoutes from './api/routes/PatientRoute.js'; const app = express(); -//middleware app.use(express.json()); app.use(cors()); -app.get("/", (req, res) => { - return res.status(234).send("hello world"); +app.get('/', (req, res) => { + return res.status(234).send('hello world'); }); -// Route handler app.use('/api/patients', patientRoutes); mongoose .connect(mongoDBUrl) .then(() => { - console.log("App connected to database"); - app.listen(PORT, () => { - console.log(`App is listening to port: ${PORT}`); - }); + console.log('App connected to database'); }) .catch((error) => { console.log(error); - }); \ No newline at end of file + }); + +if (process.env.NODE_ENV !== 'production') { + app.listen(PORT, () => { + console.log(`App is listening to port: ${PORT}`); + }); +} + +module.exports = app; \ No newline at end of file diff --git a/Backend/vercel.json b/Backend/vercel.json new file mode 100644 index 0000000..b633a24 --- /dev/null +++ b/Backend/vercel.json @@ -0,0 +1,15 @@ +{ + "version": 2, + "builds": [ + { + "src": "server.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "server.js" + } + ] +} From d2e6e2ace980401a0b31b013ef6015cc15849cb1 Mon Sep 17 00:00:00 2001 From: Pranav Pore Date: Tue, 15 Oct 2024 22:14:03 +0530 Subject: [PATCH 2/2] updated Backend/package.json for deploy commands + fixed app export --- .gitignore | 3 ++- Backend/package.json | 3 ++- Backend/server.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3b0b403..f8dd907 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ dist-ssr *.sln *.sw? -.env \ No newline at end of file +.env +.vercel diff --git a/Backend/package.json b/Backend/package.json index 603b046..39e690e 100644 --- a/Backend/package.json +++ b/Backend/package.json @@ -4,7 +4,8 @@ "type": "module", "main": "server.js", "scripts": { - "start": "nodemon server.js", + "dev": "nodemon server.js", + "start": "node server.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/Backend/server.js b/Backend/server.js index 09d4697..374d683 100644 --- a/Backend/server.js +++ b/Backend/server.js @@ -30,4 +30,4 @@ if (process.env.NODE_ENV !== 'production') { }); } -module.exports = app; \ No newline at end of file +export default app; \ No newline at end of file