forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the backend format for contact
- Loading branch information
Showing
7 changed files
with
101 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ | |
{ | ||
"image-alt": "off" | ||
} | ||
], | ||
"axe/forms": [ | ||
"default", | ||
{ | ||
"label": "off" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import zod from 'zod'; | ||
|
||
const validate = (schema) => async (req, res, next) => { | ||
try { | ||
const parsedBody = await schema.parseAsync(req.body); | ||
req.body = parsedBody; | ||
next(); | ||
} catch (err) { | ||
console.log(err); | ||
const yourerror = err.errors[0].message; | ||
res.status(400).json({ | ||
msg: yourerror, | ||
}); | ||
} | ||
try { | ||
const parsedBody = await schema.parseAsync(req.body); | ||
req.body = parsedBody; | ||
next(); | ||
} catch (err) { | ||
console.log(err); | ||
const yourerror = err.errors[0].message; | ||
res.status(400).json({ | ||
msg: yourerror, | ||
}); | ||
} | ||
module.exports = validate; | ||
}; | ||
|
||
export default validate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1932,35 +1932,52 @@ <h2 class="h2 section-title has-underline"> | |
</h2> | ||
<div class="wrapper"> | ||
<div class="contact-card"> | ||
<form action="" id="contact-form"> | ||
<form action="http://localhost:3000/contact" method="POST" id="contact-form"> | ||
<input type="text" name="name" id="name" placeholder="Your Name" required class="input-field" size="60px"> | ||
|
||
<input type="email" name="email_address" id="email" placeholder="Your Email" required class="input-field"> | ||
|
||
<input type="text" name="subject" id="subject" placeholder="Subject" required class="input-field" maxlength=100> | ||
<div id="subject-count" class="character-count">0/100</div> | ||
<!-- <div id="subject-full" class="character-full">You have reached the character limit!</div> --> | ||
|
||
<textarea name="message" id="message" placeholder="Your Message" class="input-field" maxlength=250></textarea> | ||
<div id="message-count" class="character-count">0/250</div> | ||
<!-- <div id="message-full" class="character-full">You have reached the character limit!</div> --> | ||
|
||
<button type="submit" id="sendMessageBtn" class="btn btn-primary">Send Now</button> | ||
<div id="success-message" style="display:none">Message sent successfully!</div> | ||
</form> | ||
</div> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var form = document.getElementById('contact-form'); | ||
var message = document.getElementById('message'); | ||
|
||
form.addEventListener('submit', function(event) { | ||
if (message.value.length < 50) { | ||
alert("Message length can't be less than 50 characters."); | ||
event.preventDefault(); // Prevent the form from being submitted | ||
}});}); | ||
var form = document.getElementById('contact-form'); | ||
var message = document.getElementById('message'); | ||
|
||
form.addEventListener('submit', function(event) { | ||
if (message.value.length < 50) { | ||
alert("Message length can't be less than 50 characters."); | ||
event.preventDefault(); | ||
} else { | ||
event.preventDefault(); | ||
var formData = new FormData(form); | ||
|
||
fetch(form.action, { | ||
method: form.method, | ||
body: JSON.stringify(Object.fromEntries(formData)), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}).then(response => response.json()) | ||
.then(data => { | ||
if (data.error) { | ||
alert(data.error); | ||
} else { | ||
document.getElementById('success-message').style.display = 'block'; | ||
form.reset(); | ||
} | ||
}).catch(error => { | ||
alert('Failed to send message'); | ||
}); | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
<ul class="contact-card"> | ||
<li> | ||
<p class="card-title"><lord-icon class="invert-col" src="https://cdn.lordicon.com/iikoxwld.json" trigger="hover" colors="primary:#000000" style="width:25px;height:25px"></lord-icon> Address :</p> | ||
|
@@ -1969,26 +1986,24 @@ <h2 class="h2 section-title has-underline"> | |
Kolkata, India 700054 | ||
</address> | ||
</li> | ||
|
||
<li> | ||
<p class="card-title"><lord-icon class="invert-col" src="https://cdn.lordicon.com/srsgifqc.json" trigger="hover" style="width:20px;height:20px;"></lord-icon> Phone :</p> | ||
<a href="tel:1234567890" class="card-link">+91 9124421980</a> | ||
</li> | ||
|
||
<li> | ||
<p class="card-title"><lord-icon class="invert-col" src="https://cdn.lordicon.com/xtzvywzp.json" trigger="hover" style="width:20px;height:20px;"></lord-icon> Email :</p> | ||
<a href="mailto:[email protected]" class="card-link">[email protected]</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<iframe | ||
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3686.5834653201455!2d88.40974607348684!3d22.482281936278092!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3a0273c5411d60d7%3A0x5d6e57763593194b!2sSouthern%20Cleve%20Housing%2C%2012%2C%20Bhagat%20Singh%20Nagar%2C%20Nayabad%2C%20Kolkata%2C%20West%20Bengal%20700150!5e0!3m2!1sen!2sin!4v1716043813992!5m2!1sen!2sin" | ||
style="border:0; margin-bottom:30px;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"> | ||
</iframe> | ||
|
||
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3686.5834653201455!2d88.40974607348684!3d22.482281936278092!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3a0273c5411d60d7%3A0x5d6e57763593194b!2sSouthern%20Cleve%20Housing%2C%2012%2C%20Bhagat%20Singh%20Nagar%2C%20Nayabad%2C%20Kolkata%2C%20West%20Bengal%20700150!5e0!3m2!1sen!2sin!4v1716043813992!5m2!1sen!2sin" | ||
style="border:0; margin-bottom:30px;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"> | ||
</iframe> | ||
</div> | ||
|
||
</section> | ||
|
||
|
||
<!-- Rate Us Componenet --> | ||
<div id="rate-us"> | ||
<div class="heading"> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const mongoose = require("mongoose"); | ||
const nodemailer = require("nodemailer"); | ||
const RegisterSchema = require("./assets/validation/zodschema"); | ||
const validate = require("./assets/validation/validate.schema"); | ||
const cors=require("cors") | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import mongoose from 'mongoose'; | ||
import nodemailer from 'nodemailer'; | ||
import { RegisterSchema } from './assets/validation/zodschema.js'; | ||
import validate from './assets/validation/validate.schema.js'; | ||
|
||
import cors from 'cors'; | ||
|
||
|
||
const app = express(); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); // For parsing application/x-www-form-urlencoded | ||
app.use(cors()); | ||
app.use(cors()); | ||
|
||
const MONGO_URI = "mongodb+srv://nishantkaushal0708:[email protected]/"; | ||
|
||
|
||
const dbConnect = async () => { | ||
try { | ||
await mongoose.connect(MONGO_URI, { | ||
|
@@ -133,16 +135,17 @@ dbConnect().then(() => { | |
} | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
// Subscribe endpoint | ||
app.post('/subscribe', (req, res) => { | ||
let email = req.body.email; | ||
console.log(email); | ||
res.json({ success: true, message: "Subscribed successfully" }); | ||
}); | ||
|
||
const PORT = process.env.PORT || 4000; | ||
app.listen(PORT, () => { | ||
console.log(`Server running on port ${PORT}`); | ||
}); | ||
}); | ||
|
||
|
||
app.post('/subscribe',(req,res)=>{ | ||
let email = req.body; | ||
console.log(email); | ||
}) | ||
|
||
app.listen(3000, () => console.log("Server is running on port 3000")); | ||
app.listen(4000, () => console.log("Server is running on port 3000")); |