index.js 3.03 KB
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;