index.js
2.42 KB
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
var express = require('express');
var router = express.Router();
var connection = require('./db');
var fs = require('fs');
var ejs = require('ejs');
var mapPage = fs.readFileSync('views/mapPage.ejs', 'utf8');
var findPage = fs.readFileSync('views/findPage.ejs', 'utf-8');
var dataNum = 0;
router.get('/mappage', (req, res) => {
connection.query('SELECT COUNT (*) AS cnt FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
}
console.log(results[0].cnt);
dataNum = results[0].cnt;
});
////
connection.query('SELECT * FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
} else {
var show_list = [];
for (var i = 0; i < dataNum; i++) {
show_list.push([results[i].id, results[i].oper_name, results[i].latitude, results[i].longitude, results[i].start_day, results[i].where]);
var page = ejs.render(mapPage, {
title: "show data",
data: show_list,
dataNum: dataNum,
});
}
res.send(page);
}
});
});
router.get('/findpage', (req, res) => {
connection.query('SELECT COUNT (*) AS cnt FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
}
console.log(results[0].cnt);
dataNum = results[0].cnt;
});
////
connection.query('SELECT * FROM SHOW_DATA', function (error, results, field) {
if (error) {
console.log(error);
} else {
var show_list = [];
for (var i = 0; i < dataNum; i++) {
show_list.push([results[i].id, results[i].oper_name, results[i].latitude, results[i].longitude, results[i].start_day, results[i].where]);
var page = ejs.render(findPage, {
title: "show data",
data: show_list,
dataNum: dataNum,
});
}
res.send(page);
}
});
});
//루트 페이지 (메인페이지)에서 실행됨 : title 할당하고 main.html 띄워줌.
router.get('/', function (req, res, next) {
res.render('main', { title: 'Culture Gallery' });
console.log('main 접속 성공');
});
/* GET home page. */
router.get('/login', function (req, res, next) {
res.render('login', { title: 'Login' });
console.log('로그인 페이지 접속 성공');
});
router.get('/send', function (req, res, next) {
res.render('send', { title: 'Send message' });
console.log('카카오톡 공유 메시지 접속 성공');
})
module.exports = router;