index.js
1.61 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
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;
}
});
});
router.get('/mybook', function(req, res, next){
var rows;
var query = connection.query('select * from users',function(err,row){
rows = row;
console.log(rows[1].idusers);
console.log(rows.length);
res.render('mybook', {title: '견문록 보기', rows: rows});
});
});
router.get('/test', function(req, res, next){
res.render('test', {title: 'test'});
});
module.exports = router;