Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
.vercel
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ Welcome to **RapidRoute** - your go-to open-source delivery app designed for Hac

## Technologies Used

- **Frontend**:
- **Frontend**:

- React
- Vite
- Tailwind CSS
- React Icons

- **Backend**:
- **Backend**:

- Node.js
- Express.js
- MongoDB (Mongoose)
Expand All @@ -45,35 +47,43 @@ Welcome to **RapidRoute** - your go-to open-source delivery app designed for Hac
To get a local copy of RapidRoute up and running, follow these steps:

1. Clone the repository

```bash
git clone https://github.com/yourusername/rapidroute.git
```

2. Navigate to the project directory

```bash
cd rapidroute
```

3. Install the required packages
```bash
npm install
npm run setup
# or
yarn install
yarn setup
```
4. Create .env from the .env.example in backend

```bash
cp .env.example .env
```

4. Set up the environment variables
- Create a `.env` file in the root directory and add your MongoDB connection string and other required environment variables.
5. Set up the environment variables

5. Start the development server
6. Start the development server
```bash
npm run dev
npm start
# or
yarn dev
yarn start
```

## Contributing

Contributions are what make the open-source community such a great place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Contributions are what make the open-source community such a great place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

To contribute:

Expand Down
3 changes: 3 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MONGO_URI=

JWT_SECRET=
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
.vercel
130 changes: 130 additions & 0 deletions backend/RapidRoute.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"info": {
"_postman_id": "556fff73-1823-43a6-8226-a2af6cc199ce",
"name": "RapidRoute",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "38074581"
},
"item": [
{
"name": "Auth",
"item": [
{
"name": "register",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\": \"John Doe\",\r\n \"email\": \"john@example.com\",\r\n \"password\": \"password123\"\r\n}\r\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{Host}}/api/auth/register",
"host": [
"{{Host}}"
],
"path": [
"api",
"auth",
"register"
]
}
},
"response": []
},
{
"name": "login",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"email\": \"john@example.com\",\r\n \"password\": \"password123\"\r\n}\r\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{Host}}/api/auth/login",
"host": [
"{{Host}}"
],
"path": [
"api",
"auth",
"login"
]
}
},
"response": []
},
{
"name": "profile",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "{{Authorization}}",
"type": "text"
}
],
"url": {
"raw": "{{Host}}/api/auth/profile",
"host": [
"{{Host}}"
],
"path": [
"api",
"auth",
"profile"
]
}
},
"response": []
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "Host",
"value": "",
"type": "string"
},
{
"key": "Authorization",
"value": "",
"type": "string"
}
]
}
19 changes: 19 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mongoose = require('mongoose');
const dotenv = require('dotenv');

dotenv.config();

const connectDB = async () => {
try {
const conn = await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log(`MongoDB Connected: ${conn.connection.host}`);
} catch (error) {
console.error(`Error: ${error.message}`);
process.exit(1);
}
};

module.exports = connectDB;
19 changes: 19 additions & 0 deletions backend/middleware/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const jwt = require('jsonwebtoken');

const authMiddleware = (req, res, next) => {
const token = req.header('Authorization');

if (!token) {
return res.status(401).json({ message: 'No token, authorization denied' });
}

try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next(); // Ensure this is a function to move to the next middleware or route
} catch (error) {
res.status(401).json({ message: 'Token is not valid' });
}
};

module.exports = authMiddleware;
36 changes: 36 additions & 0 deletions backend/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
date: {
type: Date,
default: Date.now,
},
});

UserSchema.pre('save', async function (next) {
if (!this.isModified('password')) return next();

const salt = await bcrypt.genSalt(10);
this.password = await bcrypt.hash(this.password, salt);
next();
});

UserSchema.methods.matchPassword = async function (enteredPassword) {
return await bcrypt.compare(enteredPassword, this.password);
};

module.exports = mongoose.model('User', UserSchema);
Loading