forked from rimmiya/WebAppProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
107 lines (93 loc) · 2.63 KB
/
index.js
File metadata and controls
107 lines (93 loc) · 2.63 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Express 기본 모듈 불러오기
var express = require('express');
// Express 객체 생성
var app = express();
var http = require('http');
var server = http.createServer(app);
// ejs view와 렌더링 설정
app.use(express.static('views'));
app.use('/img', express.static('./static/css'))
app.use('/img', express.static('./static/js'))
app.use(express.static('routes'));
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile);
// body-parser 기본 모듈 불러오기 및 설정 (POST req 해석)
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false}));
//db 오류 났는지 확인
var mysql = require('mysql');
// connection 객체 생성
var connection = mysql.createConnection({
// DB 연결 설정
host: 'webappteam.cgkc5bv4txxd.us-east-1.rds.amazonaws.com',
user : 'hdy',
password: 'han5014917',
database: 'selab'
});
connection.connect(function (err) {
if (err) {
console.error('error connection: ' + err.stack);
return;
}
// Connection 이 성공하면 로그 출력
console.log('Success DB connection');
});
// Express 서버 시작
server.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
/*
// 라우팅 처리
// '/'을 통해 들어온 요청 처리
app.get('/', function (req, res) {
res.render('index.html');
});
// login 구현
app.get('/', function(req, res) {
res.render('login.html');
});
app.post('/', function(req, res){
var id = req.body.id;
var pwd = req.body.pw;
var sql = `SELECT * FROM login WHERE id = ?`;
connection.query(sql, [id], function(error, results, fields){
if(results.length == 0){
res.render('login.html');
}
else{
var db_name = results[0].id; //'username'는 데이터베이스 칼럼 이름
var db_pwd = results[0].pw; //'pwd'또한 데이터베이스 칼럼 이름
if(pwd == db_pwd){;
res.render('index.html');
}
else{
res.render('login.html');
}
}
});
});
//회원가입 연동
app.get('/sign_up', function(req, res) {
res.render('sign_up.html');
});
app.post('/sign_up', function(req, res){
var name = req.body.name;
var id = req.body.id;
var pw = req.body.pw;
var con_pw = req.body.con_pw;
if(pw == con_pw){
//DB에 쿼리 알리기
var sql = `INSERT INTO login VALUES(?, ?, ?, ?)`;
connection.query(sql,[name, id, pw, con_pw], function(error, results, fields){
console.log(error);
});
res.redirect('login.html');
}
else{
res.render(alert("비밀번호 오류"));
res.render('sign.html');
}
});
*/
module.exports = app;