-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
132 lines (92 loc) · 2.91 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
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
let express = require('express');
let path = require('path');
let bodyParser = require('body-parser');
let fs = require('fs');
let app = express();
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = 'mongodb://localhost:27017';
// Database Name
const dbName = 'BSMS';
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.get('/', (req, res) => {
console.log('클라이언트 입장.');
});
app.post('/login', (req, res) => {
let ID_INPUT = req.body.ID;
let PW_INPUT = req.body.PASSWORD;
console.log('입력받은 아이디와 비밀번호 :' + ID_INPUT + " 과 " + PW_INPUT);
MongoClient.connect(url, (err, client) => {
assert.equal(null, err);
const db = client.db(dbName);
db.collection('users').find({
USERNAME: ID_INPUT,
PASSWORD: PW_INPUT
}).count().then((count) => {
if(count == 0){
console.log('계정정보가 존재하지 않습니다.');
res.redirect('/');
}
else{
console.log('로그인 성공');
res.redirect('/system.html');
}
})
client.close();
})
});
app.get('/system', (req, res) => {
fs.readFile(path.join(__dirname, '/public/system.html'), (err, data) => {
assert.equal(null, err);
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(data);
});
})
app.get('/system/cardcall', (req, res) => {
let CALL_NUM = req.query.CALL_NUM;
let DEFAULT = 18;
console.log('CALL_NUM = > ' + CALL_NUM);
MongoClient.connect(url, (err, client) => {
assert.equal(null, err);
const db = client.db(dbName);
if (CALL_NUM == 1) {
db.collection('busstop').find({}).limit(DEFAULT).toArray((err, docs) => {
assert.equal(null, err);
res.json(docs);
})
} else {
db.collection('busstop').find({}).skip(18 * (CALL_NUM - 1)).limit(DEFAULT).toArray((err, docs) => {
assert.equal(null, err);
res.json(docs);
})
}
client.close();
})
})
app.get('/system/location_call', (req, res) => {
res.json({lat : 36.321655 , lng : 127.378953});
})
app.post('/system/get_bs_data', (req, res) => {
let BS_ID = req.body.BS_ID;
console.log('BS_ID : ' + BS_ID);
MongoClient.connect(url, (err, client) => {
assert.equal(null, err);
const db = client.db(dbName);
db.collection('busstop').find({
BS_ID: BS_ID
}).toArray((err, docs) => {
res.json(docs);
})
client.close();
})
})
app.listen(3000, () => {
console.log('The Server is listening on port 3000!!!')
});