-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (62 loc) · 1.72 KB
/
server.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
const express = require('express');
const app = express();
const ejs = require('ejs');
const bodyParser = require('body-parser');
const router = require('./routes');
const cors = require('cors');
//const mongoose = require('mongoose');
///////////////////////////////////////////////
app.use(bodyParser.json());
app.use('/', router);
app.use(express.static('static'));
app.use(cors());
app.set('views', __dirname + '/static');
app.engine('html' , ejs.renderFile);
/////////////////////////////////////////////////
/*
mongoose.connect('mongodb://localhost:27017/chichi', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: true,
})
.then(() => {
console.log('Connected to MongoDB');
}).catch((error) => {
console.error(error);
});
const SignUpSchema = new mongoose.Schema({
id: String,
pw: String,
});
const SignUp = mongoose.model('SignUp', SignUpSchema);
app.post('/signup', async function (req, res) {
const signUp = new SignUp({ id: req.body.id, pw: req.body.pw});
await signUp.save();
console.log("Hi");
res.status(200);
res.send(signUp);
})
app.post('/signin', async function (req, res) {
const userList = await SignUp.find({ id: req.body.id });
const enteredPw = req.body.pw;
if (userList.length === 0) {
console.log("no user");
res.status(404);
res.send("No");
}
else if (userList[0].pw === enteredPw) {
res.status(200);
res.send("Yes");
console.log("Hello");
}
else {
console.log("no user");
res.status(404);
res.send("No");
}
})
*/
//////////////////////////////////////////////////
const server = app.listen(8000, () => {
console.log("We mad a server!");
})