index.js
1.89 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
var express = require('express')
var app = express()
var router = express.Router();
var path = require('path')
var requestIp = require('request-ip');
var main = require('./main/main')
var register = require('./register/index')
var login = require('./login/index')
var logout = require('./logout/index')
var board = require('./board/index')
var profile = require('./profile/index')
var about = require('./about/index')
var chat = require('./chat/chat')
// 로그용
var logString;
function getTime(){
var today = new Date();
var year = today.getFullYear();
var month = ('0' + (today.getMonth()+1)).slice(-2);
var day = ('0' + today.getDate()).slice(-2);
var hour = ('0' + today.getHours()).slice(-2);
var minute = ('0' + today.getMinutes()).slice(-2);
var second = ('0' + today.getSeconds()).slice(-2);
logString = '['+year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second+'] ';
}
// 시간 갱신용
function init(){
getTime();
setInterval(getTime, 1000)
}
init()
// URL routing
// req = request, res = respond
router.get('/', function(req, res){
try{
var ip = requestIp.getClientIp(req);
var id = req.user;
if(!id){
console.log(logString+'익명의 유저가 작업 중입니다.('+ip+')')
res.sendFile(path.join(__dirname, "../public/main.html"))
}
if(id){
var nickname = req.user.nickname;
console.log(logString+req.user.ID+'('+nickname+') 유저가 작업 중입니다.('+ip+')')
res.render('main.ejs', {'ID': id, 'nickname': nickname});
}
}
catch{
res.redirect('/main')
}
});
// router 정의
router.use('/main', main)
router.use('/register', register)
router.use('/login', login)
router.use('/logout', logout)
router.use('/board', board)
router.use('/profile', profile)
router.use('/about', about)
router.use('/chat', chat)
module.exports = router;