Skip to content

Commit

Permalink
Merge pull request #36 from PorePranav/main
Browse files Browse the repository at this point in the history
Setup backend for vercel deployment
  • Loading branch information
yazdanhaider authored Oct 15, 2024
2 parents 066fd0b + d2e6e2a commit a69e723
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dist-ssr
*.sln
*.sw?

.env
.env
.vercel
9 changes: 1 addition & 8 deletions Backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# MongoDB Connection String
DB_Url=

# Port for your application
PORT=

# JWT Secret Key
JWT_SECRET=



NODE_ENV=development
3 changes: 2 additions & 1 deletion Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
26 changes: 14 additions & 12 deletions Backend/server.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

if (process.env.NODE_ENV !== 'production') {
app.listen(PORT, () => {
console.log(`App is listening to port: ${PORT}`);
});
}

export default app;
15 changes: 15 additions & 0 deletions Backend/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.js"
}
]
}

0 comments on commit a69e723

Please sign in to comment.