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
2 changes: 2 additions & 0 deletions eventHub-dApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
33 changes: 33 additions & 0 deletions eventHub-dApp/Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage
.env

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
12 changes: 12 additions & 0 deletions eventHub-dApp/Backend/Model/URLModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mongoose from "mongoose";

const URLShortnerSchema = mongoose.Schema({
actualString: String,
shortenedString: {
type: String,
unique: true,
index: true
}
})

export const URLShortnerModel = mongoose.model("URLShortner", URLShortnerSchema);
12 changes: 12 additions & 0 deletions eventHub-dApp/Backend/config/MongooseConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mongoose from "mongoose"

const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_CONNECTION_STRING)
} catch (error) {
console.error(error.message);
process.exit(1);
}
}

export default connectDB;
87 changes: 87 additions & 0 deletions eventHub-dApp/Backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import express from "express";
import cors from "cors";
import { config } from "dotenv";
import connectDB from "./config/MongooseConnection.js";
import {URLShortnerModel} from './Model/URLModel.js';
import { SendEmail } from "./utils/SendEmail.js";

const app = express();

app.use(express.json());
app.use(cors({
origin: ["http://localhost:3000", "https://urlshortner12-ae1c0b538b3a.herokuapp.com"],
}));
config();


app.post('/api/v1/url', async (req, res) => {
const {image} = req.body;
let shortUrl = "";
for(let i=0; i<5; i++){
shortUrl += Math.floor(Math.random() * 10).toString();
shortUrl += Math.random().toString(36).substring(2,3);
}
try{
const data = await URLShortnerModel.create({
actualString: image,
shortenedString: shortUrl
})
res.status(200).json({
status: "success",
data
})
}catch(err){
res.status(400).json({
status: "error",
message: err.message
})
}
})

app.get('/api/v1/url/:shortUrl', async (req, res) => {
try{
const shortUrl = req.params.shortUrl;
if(!shortUrl) throw new Error('url not found')
const data = await URLShortnerModel.find({shortenedString : shortUrl})
res.status(200).json({
status: "success",
data
})
}catch(err){
res.status(400).json({
status: "error",
message: err.message
})
}
})

app.post('/api/v1/send-email', async (req, res) => {
const {email, name, eventName, date, time, meetingUrl} = req.body;
try{
SendEmail(email, name, eventName, date, time, meetingUrl);
res.status(200).json({
status: "success",
})
}catch(err){
res.status(400).json({
status: "error",
message: err.message
})
}
})
app.get('*', (req, res) => {
res.status(404).json({
status: "failed",
message: "Route Not Found, Not Found"
})
})

const PORT = process.env.PORT || 3004;

(function() {
connectDB().then(() => {
app.listen(PORT, () => {
console.log("Server has started on port " + PORT)
})
})
})()
Loading