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

var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : 'qmfkdnsl',
    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 ={

    'idusers' : req.body.userid,
    'address' : req.body.placeaddress,
    'contentid' : req.body.placeid,
    'title' : req.body.placename}


  console.log(tempuser);
  var query = connection.query('insert into users set ?',tempuser,function(err,result){
    if (err) {
        console.error(err);
        throw err;
    }
    console.log(query);
  });

});

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

  var rows = new Array();

  var temp1 = {

    name : "신사동떡볶이",
    place : "서울특별시 영등포구 신길7동"
  }

  var temp2 ={name : "동해떡국집", place : "서교동 1234"}
  var temp3 = {name : "앗뜨거어묵국물", place : "용인시 기흥구 어디일까"}
  var temp5 = {name : "와장창창", place : "윌집앞"}
  var temp6 = {name : "맛있는 짜장면", place : "너네집앞"}
  var temp4 = {name : "네모네모 오징어", place : "영등포경찰서"}
  var temp7 = {name : "스타벅스", place : "서울특별시 영등포구 여의도동"}

  rows.push(temp1);
  rows.push(temp2);
//  rows.push(temp3);
//  rows.push(temp4);
//  rows.push(temp5);
  rows.push(temp6);
  rows.push(temp7);

  res.render('mybook', {title: '견문록 보기', rows : rows});

});

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

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

});

module.exports = router;