Showing
5 changed files
with
122 additions
and
0 deletions
db/db_board.js
0 → 100644
1 | +var mysql = require('mysql'); | ||
2 | +var config = require('./db_info').board; | ||
3 | + | ||
4 | +module.exports=function(){ | ||
5 | + return{ | ||
6 | + init: function(){ | ||
7 | + return mysql.createConnection({ | ||
8 | + host:'localhost', | ||
9 | + port:'3306', | ||
10 | + user:'root', | ||
11 | + password:'2016104101', | ||
12 | + database:'board' | ||
13 | + // host:config.host, | ||
14 | + // port:config.port, | ||
15 | + // user:config.user, | ||
16 | + // password:config.password, | ||
17 | + // database:config.database | ||
18 | + }) | ||
19 | + } | ||
20 | + } | ||
21 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
db/db_info.js
0 → 100644
1 | +module.exports=(function(){ | ||
2 | + return{ | ||
3 | + board:{ | ||
4 | + host:'localhost', | ||
5 | + port:'3306', | ||
6 | + user:'root', | ||
7 | + password:'2016104101', | ||
8 | + database:'board' | ||
9 | + }, | ||
10 | + example: { | ||
11 | + host: '', | ||
12 | + port: '', | ||
13 | + user: '', | ||
14 | + password: '', | ||
15 | + database: '' | ||
16 | + }, | ||
17 | + } | ||
18 | +}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
public/board.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="en"> | ||
3 | + <head> | ||
4 | + <meta charset="utf-8" /> | ||
5 | + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> | ||
6 | + <meta name="description" content="" /> | ||
7 | + <meta name="author" content="" /> | ||
8 | + <title>묵호 - 놀이터</title> | ||
9 | + <!-- Favicon--> | ||
10 | + <link rel="icon" type="image/x-icon" href="../assets/favicon.ico" /> | ||
11 | + <!-- Bootstrap icons--> | ||
12 | + <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" type="text/css" /> | ||
13 | + <!-- Google fonts--> | ||
14 | + <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" /> | ||
15 | + <!-- Core theme CSS (includes Bootstrap)--> | ||
16 | + <link href="../css/styles.css" rel="stylesheet" /> | ||
17 | + </head> | ||
18 | + <body> | ||
19 | + | ||
20 | + </body> | ||
21 | + | ||
22 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
router/board/index.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +var router = express.Router(); | ||
3 | +var mysql = require('mysql'); | ||
4 | +var path = require('path') // 상대경로 | ||
5 | +var mysql_odbc = require('../../db/db_board')(); | ||
6 | +var board = mysql_odbc.init(); | ||
7 | + | ||
8 | + | ||
9 | +router.get('/:page', function(req, res, next) { | ||
10 | + var page = req.params.page; | ||
11 | + var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " + | ||
12 | + "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board"; | ||
13 | + | ||
14 | + board.query(sql, function(err,rows) { | ||
15 | + if (err) console.error("err : " + err); | ||
16 | + res.render('list.ejs', {title: '게시판 리스트', rows: rows}) | ||
17 | + | ||
18 | + }) | ||
19 | +}); | ||
20 | + | ||
21 | +router.get('/', function(req,res,next){ | ||
22 | + res.redirect('/board/1') | ||
23 | +}) | ||
24 | + | ||
25 | +module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
views/list.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | +<head> | ||
4 | + <title><%= title %></title> | ||
5 | + <link rel='stylesheet' href='/stylesheets/style.css'/> | ||
6 | +</head> | ||
7 | +<body> | ||
8 | +<h1><%= title %></h1> | ||
9 | +<a href="/board/write">글쓰기</a> | ||
10 | +<table border="1"> | ||
11 | + <tr> | ||
12 | + <td>번호</td> | ||
13 | + <td>작성자</td> | ||
14 | + <td>제목</td> | ||
15 | + <td>조회수</td> | ||
16 | + <td>수정일</td> | ||
17 | + <td>등록일</td> | ||
18 | + </tr> | ||
19 | + <% | ||
20 | + for(var i=0; i<rows.length; i++) | ||
21 | + { | ||
22 | + var data = rows[i]; | ||
23 | + %> | ||
24 | + <tr> | ||
25 | + <td><%=data.idx%></td> | ||
26 | + <td><%=data.name%></td> | ||
27 | + <td><a href="/board/read/<%=data.idx%>"><%=data.title%></a></td> | ||
28 | + <td><%=data.hit%></td> | ||
29 | + <td><%=data.modidate%></td> | ||
30 | + <td><%=data.regdate%></td> | ||
31 | + </tr> | ||
32 | + <%}%> | ||
33 | +</table> | ||
34 | +</body> | ||
35 | +</html> | ||
36 | + |
-
Please register or login to post a comment