Showing
1 changed file
with
53 additions
and
51 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | +var path = require('path'); | ||
3 | +var bodyParser = require('body-parser'); | ||
4 | +var request = require('request'); | ||
5 | +var fs = require('fs'); | ||
6 | +var ejs = require('ejs'); | ||
7 | +var indexRouter = require('./routes/index'); | ||
8 | + | ||
9 | +var app = express(); | ||
10 | +const PORT = 80; | ||
11 | + | ||
12 | +app.set('views', path.join(__dirname, 'views')); | ||
13 | +app.set('view engine', 'ejs'); | ||
14 | + | ||
15 | +app.use(express.static(path.join(__dirname, 'public'))); | ||
16 | +app.use(bodyParser.json()); | ||
17 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
18 | + | ||
19 | +app.use('/', indexRouter); | ||
20 | + | ||
21 | +app.listen(PORT, function(){ | ||
22 | + console.log('Code run in https://localhost:'+PORT); | ||
23 | +}); | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | +/* | ||
33 | +var express = require('express'); | ||
2 | var app = express(); | 34 | var app = express(); |
3 | var bodyParser = require('body-parser'); | 35 | var bodyParser = require('body-parser'); |
4 | var fs = require('fs'); | 36 | var fs = require('fs'); |
37 | +const ejs = require('ejs'); | ||
38 | +var engines = require('consolidate'); | ||
5 | const PORT = 80; | 39 | const PORT = 80; |
6 | 40 | ||
41 | +// 크롤링 한 list 받아오기 | ||
7 | const xports = require('./test1.js'); | 42 | const xports = require('./test1.js'); |
8 | const zum = require('./test2.js'); | 43 | const zum = require('./test2.js'); |
9 | const chosun = require('./test3.js'); | 44 | const chosun = require('./test3.js'); |
... | @@ -14,57 +49,24 @@ const yna = require('./test4.js'); | ... | @@ -14,57 +49,24 @@ const yna = require('./test4.js'); |
14 | //console.log(chosun.chosun); | 49 | //console.log(chosun.chosun); |
15 | //console.log(yna.yna); | 50 | //console.log(yna.yna); |
16 | 51 | ||
17 | -app.get('/', function(req, res){ | 52 | +// router 설정 |
18 | - | 53 | +var indexRouter = require('./routes/index'); |
19 | - var newslist = ''; | 54 | + |
20 | - var newsobject = xports.xports; | 55 | +app.use(express.json()); |
21 | - console.log(newsobject[0].url); | 56 | +app.use(express.urlencoded({extended:false})); |
22 | - for(var i = 0; i < newsobject.length; i++){ | 57 | + |
23 | - newslist = newslist +` | 58 | +app.use(express.static('public')) |
24 | - <li> | ||
25 | - <div class='item'> | ||
26 | - <div class='info'> | ||
27 | - <span class='time'>${newsobject[i].datetime}</span> | ||
28 | - </div> | ||
29 | - <div class='img'> | ||
30 | - <a> | ||
31 | - <img src = ${newsobject[i].image_url}> | ||
32 | - </a> | ||
33 | - </div> | ||
34 | - <div class='news'> | ||
35 | - <a href = ${newsobject[i].url}> | ||
36 | - <strong>${newsobject[i].title}</strong> | ||
37 | - </a> | ||
38 | - <p> | ||
39 | - ${newsobject[i].summary} | ||
40 | - </p> | ||
41 | - </div> | ||
42 | - </div> | ||
43 | - </li>`; | ||
44 | - } | ||
45 | - | ||
46 | - var html = ` | ||
47 | - <!DOCTYPE html> | ||
48 | - <html> | ||
49 | - | ||
50 | - <head> | ||
51 | - <meta charset="utf-8"> | ||
52 | - <title>ossswoo.tk</title> | ||
53 | - </head> | ||
54 | - | ||
55 | - <body> | ||
56 | - <div class = 'main'> | ||
57 | - <div class = 'center'> | ||
58 | - <div> | ||
59 | - ${newslist} | ||
60 | - </div> | ||
61 | - </div> | ||
62 | - </div> | ||
63 | - </body> | ||
64 | - </html>`; | ||
65 | - res.send(html); | ||
66 | -}); | ||
67 | 59 | ||
60 | +app.set('news', __dirname + '/news'); | ||
61 | +//화면 engine 설정 | ||
62 | +app.engine('html', engines.mustache); | ||
63 | +app.set('news engine', 'ejs'); | ||
64 | + | ||
65 | +// main 화면 | ||
66 | +app.use('/', indexRouter); | ||
67 | + | ||
68 | +// 서버 생성 | ||
68 | app.listen(PORT, function(){ | 69 | app.listen(PORT, function(){ |
69 | console.log('Code run in https://localhost:'+PORT); | 70 | console.log('Code run in https://localhost:'+PORT); |
70 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
71 | +}); | ||
72 | +*/ | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment