-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (45 loc) · 1.31 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const path = require('path');
const app = express();
const port = 80;
const bodyparser = require('body-parser');
const mongoose = require('mongoose');
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/DentalWebContact');
const contactSchema = new mongoose.Schema({
Name: String,
Email: String,
Phone: String,
Subject: String,
Message: String,
});
const Contact = mongoose.model('Contact', contactSchema);
//EXPRESS CONFIG
app.use('/static', express.static('static'));
app.use(express.urlencoded());
//PUG CONFIG
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
//Endpoints
app.get('/', (req,res)=>{
const parameters = {};
res.status(200).render('home.pug', parameters);
})
app.get('/contact', (req,res)=>{
const parameters = {};
res.status(200).render('contact.pug', parameters);
})
app.post('/contact', (req,res)=>{
var ContactData = new Contact(req.body);
ContactData.save().then(()=>{
res.status(200).render('contact.pug');
}).catch(()=>{
res.status(400).send("There was some error. Try again later")
});
})
//SERVER STARTING
app.listen(port, ()=>{
console.log(`Application started successfully on port ${port}`);
});
}