-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
84 lines (79 loc) · 2.48 KB
/
express.js
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
//해당 폴더에 설치 되어 있는 express모듈을 가져옴.
const express = require('express');
const port = 80;
const mysql = require('mysql');
const dbInfo = require('./db_info.js');
const bdParse = require( 'body-parser' );
var con = mysql.createConnection(dbInfo);
var expApp = express();
expApp.set("port",port);
expApp.use(bdParse.urlencoded({ extended: false }));
expApp.use(bdParse.json());
var func1 = function(req,res){
var id = rea.query.id;
console.log(id + '를 요청하셨군요');
res.send('안녕하세요' + id + '님');
}
expApp.get("/", func1);
expApp.get("/test", function(req,res){
console.log(id + '를 요청하셨군요');
res.send('나에게 테스트를 주었구나');
})
/*
expApp.get('/user', function(req,res){
con.query('select * from user_info' ,
function(err,rows){
if(err) throw err;
console.log(rows);
var resText ="<table border='1'>";
for(var key in rows){
resText+="<tr>";
var row = rows[key];
for(var col in row){
resText += "<td>" + col + ":" + row[col] +",";
}
resText +="</tr>";
}
resText += "</table>";
res.send(resText);
})
})
*/
/*
expApp.get("/", function(req,res){
res.send('hello express');
})
*/
var urlForUserSearch = "/user";
var funcForUserList = function(req,res){
var userId = req.query.id;
var userPwd = req.query.pwd;
var resText = "";
if(!userId){
res.send = ( "유저아이디를 입력해주세요" );
}else if(!userPwd){
res.send = ( "비밀번호를 입력해주세요.");
}else{
var sql = 'select * from user_info where userId=?';
var values = [userId];
con.query(sql,values,function(err,rows){
if(err)throw err;
if(rows.length==0){
resText = "입력하신 id:" + userId;
resText += "와 일치하는 id가 없습니다.";
}else{
console.log("dbPwd = " + rows[0].userPwd);
console.log(userPwd!=rows[0].userPwd);
if(userPwd!= rows[0].userPwd){
resText = "입력하신 비밀번호가 틀립니다.";
}else{
resText += userId + "님 환영합니다.";
}
}
console.log(resText);
res.send(resText);
});
}
}
expApp.get(urlForUserSearch, funcForUserList);
expApp.listen(expApp.get("port"));