Showing
1 changed file
with
33 additions
and
29 deletions
| ... | @@ -9,6 +9,8 @@ const conf = JSON.parse(data); | ... | @@ -9,6 +9,8 @@ const conf = JSON.parse(data); |
| 9 | const mysql = require('mysql'); | 9 | const mysql = require('mysql'); |
| 10 | const sslport = 23023; | 10 | const sslport = 23023; |
| 11 | var cookieSession = require('cookie-session') | 11 | var cookieSession = require('cookie-session') |
| 12 | +var schedule = require('node-schedule'); | ||
| 13 | + | ||
| 12 | 14 | ||
| 13 | app.use(bodyParser.json()); | 15 | app.use(bodyParser.json()); |
| 14 | app.use(bodyParser.urlencoded({ extended: true })); | 16 | app.use(bodyParser.urlencoded({ extended: true })); |
| ... | @@ -18,8 +20,6 @@ app.use('/css', express.static(__dirname + '/css')); | ... | @@ -18,8 +20,6 @@ app.use('/css', express.static(__dirname + '/css')); |
| 18 | app.use('/html', express.static(__dirname + '/html')); | 20 | app.use('/html', express.static(__dirname + '/html')); |
| 19 | app.use('/img', express.static(__dirname + '/img')); | 21 | app.use('/img', express.static(__dirname + '/img')); |
| 20 | 22 | ||
| 21 | -var count = 0; | ||
| 22 | - | ||
| 23 | app.set('trust proxy', 1); | 23 | app.set('trust proxy', 1); |
| 24 | 24 | ||
| 25 | app.use(cookieSession({ | 25 | app.use(cookieSession({ |
| ... | @@ -41,34 +41,25 @@ const connection = mysql.createConnection({ | ... | @@ -41,34 +41,25 @@ const connection = mysql.createConnection({ |
| 41 | 41 | ||
| 42 | }); | 42 | }); |
| 43 | 43 | ||
| 44 | +var date = new Date(); | ||
| 45 | +let year = date.getFullYear(); | ||
| 46 | +let month = date.getMonth(); | ||
| 47 | +let day = date.getDate(); | ||
| 48 | +var count = 0; | ||
| 49 | + | ||
| 44 | connection.connect(); | 50 | connection.connect(); |
| 45 | 51 | ||
| 46 | -async function DBUpdate(year, month, day) { | 52 | +schedule.scheduleJob({ hour: 23, minute: 59, second: 1 }, function () { |
| 47 | - await console.log(yaer + " " + month + " " + day); | 53 | + console.log(year + " " + month + " " + day); |
| 48 | - await connection.query( | 54 | + connection.query( |
| 49 | - `INSERT INTO visiter VALUES (${date.getFullYear()}, ${date.getMonth()},${date.getDate()}, ${count});` | 55 | + `INSERT INTO visiter VALUES (${year}, ${month + 1},${day}, ${count});` |
| 50 | ); | 56 | ); |
| 51 | - count = await 0; | 57 | + count = 0; |
| 52 | -} | 58 | +}); |
| 53 | - | ||
| 54 | -var date = new Date(); | ||
| 55 | 59 | ||
| 56 | app.get('/', (req, res) => { | 60 | app.get('/', (req, res) => { |
| 57 | - let year = date.getFullYear(); | ||
| 58 | - let month = date.getMonth(); | ||
| 59 | - let day = date.getDate(); | ||
| 60 | var today = year + " " + month + " " + day; | 61 | var today = year + " " + month + " " + day; |
| 61 | 62 | ||
| 62 | - setInterval(() => { | ||
| 63 | - date.setSeconds(date.getSeconds() + 1); | ||
| 64 | - var hours = date.getHours(); | ||
| 65 | - var minutes = date.getMinutes(); | ||
| 66 | - var seconds = date.getSeconds(); | ||
| 67 | - console.log(`${hours}:${minutes}:${seconds}`); | ||
| 68 | - if (hours === 23 && minutes === 59 && seconds === 59) { | ||
| 69 | - DBUpdate(year, month, day); | ||
| 70 | - } | ||
| 71 | - }, 1000); | ||
| 72 | console.log(req.session.lastVisit); | 63 | console.log(req.session.lastVisit); |
| 73 | if (req.session.lastVisit != today) { | 64 | if (req.session.lastVisit != today) { |
| 74 | req.session.lastVisit = today; | 65 | req.session.lastVisit = today; |
| ... | @@ -76,16 +67,28 @@ app.get('/', (req, res) => { | ... | @@ -76,16 +67,28 @@ app.get('/', (req, res) => { |
| 76 | } | 67 | } |
| 77 | 68 | ||
| 78 | fs.readFile(path.join(__dirname, 'html', 'index.html'), (err, data) => { | 69 | fs.readFile(path.join(__dirname, 'html', 'index.html'), (err, data) => { |
| 70 | + try { | ||
| 79 | res.writeHead(200, { 'Content-Type': 'text/html' }); | 71 | res.writeHead(200, { 'Content-Type': 'text/html' }); |
| 80 | console.log(count); | 72 | console.log(count); |
| 81 | res.end(data); | 73 | res.end(data); |
| 74 | + } catch (err) { | ||
| 75 | + res.writeHead(404, () => { | ||
| 76 | + console.log("Page Not Found!") | ||
| 77 | + }); | ||
| 78 | + } | ||
| 82 | }) | 79 | }) |
| 83 | }); | 80 | }); |
| 84 | 81 | ||
| 85 | app.get('/detail.html', (req, res) => { | 82 | app.get('/detail.html', (req, res) => { |
| 86 | fs.readFile(path.join(__dirname, 'html', 'detail.html'), (err, data) => { | 83 | fs.readFile(path.join(__dirname, 'html', 'detail.html'), (err, data) => { |
| 84 | + try { | ||
| 87 | res.writeHead(200, { 'Content-Type': 'text/html' }); | 85 | res.writeHead(200, { 'Content-Type': 'text/html' }); |
| 88 | res.end(data); | 86 | res.end(data); |
| 87 | + } catch (err) { | ||
| 88 | + res.writeHead(404, () => { | ||
| 89 | + console.log("Page Not Found!") | ||
| 90 | + }); | ||
| 91 | + }; | ||
| 89 | }); | 92 | }); |
| 90 | }); | 93 | }); |
| 91 | 94 | ||
| ... | @@ -101,16 +104,18 @@ app.get('/api/visiters', (req, res) => { | ... | @@ -101,16 +104,18 @@ app.get('/api/visiters', (req, res) => { |
| 101 | 104 | ||
| 102 | app.get('/statistics.html', (req, res) => { | 105 | app.get('/statistics.html', (req, res) => { |
| 103 | fs.readFile(path.join(__dirname, 'html', 'statistics.html'), (err, data) => { | 106 | fs.readFile(path.join(__dirname, 'html', 'statistics.html'), (err, data) => { |
| 107 | + try { | ||
| 104 | res.writeHead(200, { 'Content-Type': 'text/html' }); | 108 | res.writeHead(200, { 'Content-Type': 'text/html' }); |
| 105 | res.end(data); | 109 | res.end(data); |
| 106 | - }) | 110 | + } catch (err) { |
| 111 | + res.writeHead(404, () => { | ||
| 112 | + console.log("Page Not Found!") | ||
| 113 | + }); | ||
| 114 | + }; | ||
| 115 | + }); | ||
| 107 | }) | 116 | }) |
| 108 | 117 | ||
| 109 | -app.listen(sslport, () => { | ||
| 110 | - console.log(`https server listening on port ${sslport}`) | ||
| 111 | -}) | ||
| 112 | 118 | ||
| 113 | -/* | ||
| 114 | try { | 119 | try { |
| 115 | const options = { | 120 | const options = { |
| 116 | key: fs.readFileSync('./keys/private.pem'), | 121 | key: fs.readFileSync('./keys/private.pem'), |
| ... | @@ -125,4 +130,3 @@ try { | ... | @@ -125,4 +130,3 @@ try { |
| 125 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | 130 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); |
| 126 | console.log(error); | 131 | console.log(error); |
| 127 | } | 132 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 128 | -*/ | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment