-
Notifications
You must be signed in to change notification settings - Fork 3
/
Backend.js
174 lines (141 loc) · 4.57 KB
/
Backend.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const app = express();
const port = process.env.PORT || 3000;
// console.log(path.join(__dirname, 'Public/index.html'))
app.use(bodyParser.json())
app.use(express.static(path.join(__dirname + '/Public')));
// console.log(path.join(__dirname + '/public'));
app.use(bodyParser.urlencoded({
extended:true
}))
mongoose.connect('mongodb+srv://yashmangal:[email protected]/Portfolio', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
var db = mongoose.connection;
// console.log(path.join(__dirname, 'Public/index.html'));
// console.log(path.join(__dirname, '/Public/index.html'));
app.get("/", (req, res)=>{
res.statusCode = 200;
(res.sendFile(path.join(__dirname, '/Public/index.html')));
})
app.get("/index.html", (req, res)=>{
res.statusCode = 200;
(res.sendFile(path.join(__dirname, '/Public/index.html')));
})
app.get("/UxDesignProjects.html", (req, res)=>{
res.statusCode = 200;
(res.sendFile(path.join(__dirname, '/Public/UxDesignProjects.html')));
})
app.get("/WebDProjects.html", (req, res)=>{
res.statusCode = 200;
(res.sendFile(path.join(__dirname, '/Public/WebDProjects.html')));
})
app.get("/yash", (req, res)=>{
res.statusCode = 200;
res.send("Hey yash");
})
// console.log(path.json(__dirname, 'index.html'))
// console.log(path.join(__dirname, 'Public/index.html'));
// db.once('connection', ()=>{
// console.log('Ah, we have our first user!');
// })
// db.on('error', ()=>{
// console.log('Sorry, Error in connecting to Database!')
// })
db.on('error',()=>console.log("Error in Connecting to Database"));
db.once('open',()=>console.log("Connected to Database"))
// Store Date For Main Site DB
app.post('/submit', (req, res)=>{
var name = req.body.name;
var email = req.body.email;
var drop_line = req.body.drop_line;
var data = {
"name": name,
"email": email,
"drop_line": drop_line
}
db.collection('users').insertOne(data, (err, collection)=>{
if (err) {
throw err;
}
console.log("Record Inserted Successfully");
});
setTimeout(() => {
console.log('Site reload')
return res.redirect('index.html') // changes
}, 3000);
})
// Store Date For UI/UX Design Project DB
app.post('/submit_Ux', (req, res)=>{
var name = req.body.name;
var email = req.body.email;
var drop_line = req.body.drop_line;
var data = {
"name": name,
"email": email,
"drop_line": drop_line
}
db.collection('users_Ux').insertOne(data, (err, collection)=>{
if (err) {
throw err;
}
console.log("Record Inserted Successfully In UI/UX Design DB");
});
setTimeout(() => {
console.log('Site reload of UX Design Projects')
return res.redirect('UxDesignProjects.html') // changes
}, 3000);
})
// Store Date For Web Developer Project DB
app.post('/submit_WebD', (req, res)=>{
var name = req.body.name;
var email = req.body.email;
var drop_line = req.body.drop_line;
var data = {
"name": name,
"email": email,
"drop_line": drop_line
}
db.collection('users_WebD').insertOne(data, (err, collection)=>{
if (err) {
throw err;
}
console.log("Record Inserted Successfully In WebD Project DB");
});
setTimeout(() => {
console.log('Site reload of WebD Projects')
return res.redirect('WebDProjects.html') // changes
}, 3000);
})
// const server = http.createServer((req, res)=>{
// res.setHeader('Content-Type', 'text-html', 'style-css')
// // res.yash();
// console.log(req.url)
// if (req.url == '/') {
// res.statusCode = 200;
// const index = fs.readFileSync('index.html');
// res.end(index.toString());
// }
// else if(req.url == '/UxDesignProjects.html'){
// res.statusCode = 200;
// const uxproject = fs.readFileSync('UxDesignProjects.html')
// res.end(uxproject.toString())
// }
// else if(req.url == '/WebDProjects.html'){
// res.statusCode = 200;
// const webdproject = fs.readFileSync('WebDProjects.html')
// res.end(webdproject.toString());
// }
// else{
// res.statusCode = 404;
// res.end('<h2>Not Found</h2>')
// }
// })
app.listen(port, ()=>{
console.log(`Server is listening on port ${port}`)
});
// console.log('Server is listening on PORT 3000');