router.js 913 Bytes
const express = require('express')
const router = express.Router()
const fs=require('fs')
const passport = require('./passport.js')
const path = require('path');

router.get('/', (req, res) => {
    res.render('index', {title: "인덱스"})
})

//로그인창
router.post('/', passport.authenticate('local-login', {
    successRedirect : '/loginSuccess',
    failureRedirect : '/loginFail',
    failureFlash : true
}))

//로그인성공
router.get('/loginSuccess', (req, res) => {
    res.render('loginSuccess')
})

//로그인실패
router.get('/loginFail', (req, res) => {
    res.render('loginFail')
})

//Express에서 정적파일(ex: main.html, main.js)들을 사용할경우
//경로를 미리 제시해 주는 부분
router.use(express.static(__dirname + '/main'));

//메인화면
router.get('/main', (req, res)=>{
    res.sendFile(path.join(__dirname+'/main/main.html'));
  })

module.exports = router