Skip to content

Commit

Permalink
14.1.정리정돈-topic 1
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Jun 15, 2018
1 parent 20caeab commit 588151d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
16 changes: 16 additions & 0 deletions lib/topic.js
@@ -0,0 +1,16 @@
var db = require('./db');
var template = require('./template.js');

exports.home = function(request, response){
db.query(`SELECT * FROM topic`, function(error,topics){
var title = 'Welcome';
var description = 'Hello, Node.js';
var list = template.list(topics);
var html = template.HTML(title, list,
`<h2>${title}</h2>${description}`,
`<a href="/create">create</a>`
);
response.writeHead(200);
response.end(html);
});
}
15 changes: 3 additions & 12 deletions main.js
Expand Up @@ -3,24 +3,15 @@ var url = require('url');
var qs = require('querystring');
var template = require('./lib/template.js');
var db = require('./lib/db');
var topic = require('./lib/topic');

var app = http.createServer(function(request,response){
var _url = request.url;
var queryData = url.parse(_url, true).query;
var pathname = url.parse(_url, true).pathname;
if(pathname === '/'){
if(queryData.id === undefined){
db.query(`SELECT * FROM topic`, function(error,topics){
var title = 'Welcome';
var description = 'Hello, Node.js';
var list = template.list(topics);
var html = template.HTML(title, list,
`<h2>${title}</h2>${description}`,
`<a href="/create">create</a>`
);
response.writeHead(200);
response.end(html);
});
topic.home(request, response);
} else {
db.query(`SELECT * FROM topic`, function(error,topics){
if(error){
Expand Down Expand Up @@ -165,4 +156,4 @@ var app = http.createServer(function(request,response){
response.end('Not found');
}
});
app.listen(3000);
app.listen(3000);

0 comments on commit 588151d

Please sign in to comment.