index.js
3.03 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
90
91
92
93
94
95
96
97
98
var express = require('express');
var mysql = require('mysql');
var dbconfig = require('../config/database.js');
var dbconfig2 = require('../config/database2.js');
var dbconfig3 = require('../config/database3.js');
var pool = mysql.createPool(dbconfig3);
var bodyParser = require('body-parser');
var router = express.Router();
// configuration ===============================================================
router.get('/first',function(req,res){
res.render('first',{title : "첫번째 화면~"});
})
router.get('/', function(req, res){
res.render('index',{title: "첫화면"});
});
router.get('/list', function(req, res){
res.render('list',{title :"게시판"});
});
router.get('/res', function(req, res){
res.render('reservation',{title :"예약"});
});
router.post('/res',function(req, res){
var creater_id = req.body.creater_id;
var phone = req.body.phone;
var email = req.body.email;
var num = req.body.num;
var restime = req.body.restime;
var resmin = req.body.resmin;
var content = req.body.content;
pool.getConnection(function (err, connection)
{
// Use the connection
var sqlForInsertBoard = "insert into menu(creater_id, phone, email, num, restime, resmin, content) values('"+creater_id+"', '"+phone+"', '"+email+"','"+num+"','"+restime+"','"+resmin+"', '"+content+"')";
connection.query(sqlForInsertBoard, function (err, rows) {
if (err) console.error("err : " + err);
console.log("rows : " + JSON.stringify(rows));
res.redirect('/resconfirm');
connection.release();
// Don't use the connection here, it has been returned to the pool.
});
});
})
router.get('/resconfirm', function(req, res){
res.render('resconfirm',{title : "예약확인"});
})
router.get('/write2',function(req,res){
res.render('write',{title : "게시판"});
res.redirect('/');
connection.release();
})
router.post('/write2',function(req, res){
var creater_id = req.body.creater_id;
var title = req.body.title;
var content = req.body.content;
pool.getConnection(function (err, connection)
{
// Use the connection
var sqlForInsertBoard = "insert into db2(creater_id, title, content) values('"+creater_id+"', '"+title+"', '"+content+"')";
connection.query(sqlForInsertBoard, function (err, rows) {
if (err) console.error("err : " + err);
console.log("rows : " + JSON.stringify(rows));
res.redirect('/');
connection.release();
// Don't use the connection here, it has been returned to the pool.
});
});
})
router.get('/persons', function(req, res){
connection.query('SELECT * from Persons', function(err, rows) {
if(err) throw err;
console.log('The solution is: ', rows);
res.send(rows);
});
});
router.get('/page',function(req, res){
connection.query('SELECT * from db2', function(err, rows) {
if(err) throw err;
console.log('The solution is: ', rows);
res.send(rows);
});
});
module.exports = router;