forked from shubha987/tUneBOx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (78 loc) · 2.37 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
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
const path = require("path");
const express = require("express");
const fs=require("fs");
const app = express();
const mongoose = require('mongoose');
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
main().catch(err => console.log(err));
const port = 80;
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/details',{ useNewUrlParser: true, useUnifiedTopology: true });
console.log("connected")
}
const loginSchema = new mongoose.Schema({
username: String,
password:String
});
const registerSchema = new mongoose.Schema({
name: String,
age: String,
username: String,
password:String
});
const contactSchema = new mongoose.Schema({
usercontact: String,
passlogin:String,
message:String
});
const Userlogin = mongoose.model('Loguser', loginSchema);
const Userregister = mongoose.model('reguser', registerSchema);
const Usercontact = mongoose.model('contuser', contactSchema);
app.use(express.static(path.join(__dirname, '/')));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'index.html'));
});
app.get("/about", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'about.html'));
});
app.get("/instruments", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'instruments.html'));
});
app.get("/contact", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'contact.html'));
});
app.get("/blog", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'blog.html'));
});
app.post("/submit", (req, res) => {
let registerdata =new Userregister(req.body);
console.log(registerdata);
registerdata.save().then(()=>{
res.redirect('/');
}).catch(()=>{
res.status(404).send("Error 404 not found");
});
});
app.post("/login", (req, res) => {
let logindata =new Userlogin(req.body);
console.log(logindata);
logindata.save().then(()=>{
res.redirect('/');
}).catch(()=>{
res.status(404).send("Error 404 not found");
});
});
app.post("/contactsub", (req, res) => {
console.log("POST request received:", req.body);
let contactdata =new Usercontact(req.body);
console.log(contactdata);
contactdata.save().then(()=>{
res.redirect('/contact');
}).catch(()=>{
res.status(404).send("Error 404 not found");
});
});
app.listen(port, () => {
console.log(`Port 80 running at http://localhost:${port}`);
});