index.js 1.99 KB
var express = require('express');
var mysql = require('mysql');
var router = express.Router();

var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'admin',
    password : 'admin',
    database : 'ossprojectdb'
});

connection.connect();
/* GET home page. */
router.get('/index', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/', function(req, res, next) {
  res.render('main', { title: '맛집 견문록' });
});


router.get('/map', function(req, res, next){

  var user = {
    iduser : "abc",
    username : "김정은",
    password : "qmfkdnsl",
    email : "bfghg@naver.com"

  }
  res.render('map', {title: '맛집 도장찍기', user : user});

});

router.get('/home', function(req,res,next){

  res.render('main', {title: '맛집견문록'});
});


router.post('/map', function(req, res){


  var tempuser ={

    'email' : req.body.useremail,
    'contentid' : req.body.id,
    'title' : req.body.title,
    'address' : req.body.address}


  console.log(tempuser);

  var query = connection.query('insert into history set ?',tempuser,function(err,result){
    if (err) {
        console.error(err);
        throw err;
    }
  });
  console.log("success insert!");
  res.redirect('/map')
});

router.get('/mybook', function(req, res, next){

  var rows;
  var query = connection.query('select * from history h, users u WHERE h.email = u.email',function(err,row){

    rows = row;
    //console.log(rows[1].idusers);
    //console.log(rows.length);
    res.render('mybook', {title: '견문록 보기', rows: rows});

  });


});

router.get('/history', function(req, res, next){

  var rows;
  var query = connection.query('select contentid from history h, users u WHERE h.email = u.email',function(err,row){

    rows = row;
    //console.log(rows[1].idusers);
    //console.log(rows.length);
    res.send({rows: rows});

  });


});

router.get('/test', function(req, res, next){

res.render('test', {title: 'test'});

});

module.exports = router;