Showing
1 changed file
with
32 additions
and
13 deletions
| 1 | const express = require('express'); | 1 | const express = require('express'); |
| 2 | -const fs = require('fs'); | ||
| 3 | const path = require('path'); | 2 | const path = require('path'); |
| 4 | const app = express(); | 3 | const app = express(); |
| 5 | 4 | ||
| 5 | +//화면 별 router 연결, 라우터 호출해서 페이지를 불러오는데 사용함. | ||
| 6 | +var mainRouter = require('./routes/main') //호출시 main.js 실행 (main.js : title 할당하고 main.html 열어줌) | ||
| 7 | +var loginRouter = require('./routes/login') | ||
| 6 | //디폴트 포트 값 : 8000 | 8 | //디폴트 포트 값 : 8000 |
| 7 | app.set('port', process.env.PORT || 8000); | 9 | app.set('port', process.env.PORT || 8000); |
| 8 | 10 | ||
| 9 | -app.get('/', (req, res) => { | 11 | +//ejs (html포맷) 파일을 웹사이트에 view로 띄워주기 위한 view engine 설정. |
| 10 | - //res.send('Server is working'); | 12 | +app.set('views', path.join(__dirname, 'views')); |
| 11 | - res.sendFile(path.join(__dirname, './public/html/main.html')); | 13 | +app.set('view engine', 'ejs'); |
| 12 | - console.log(app.get('port'), '번 포트 대기 중'); | 14 | +app.engine('html', require('ejs').renderFile); |
| 13 | -}); | 15 | + |
| 14 | -app.get('/login', (req, res) => { | 16 | +//각각의 요청에서 router 호출해서 page를 전환함. |
| 15 | - console.log('로그인 페이지 오픈 시도됨.'); | 17 | +app.use('/', mainRouter); |
| 16 | - fs.readFile('./public/html/login.html', function (err, data) { | 18 | +app.use('/login', loginRouter); |
| 17 | - res.writeHead(200, { 'Content-Type': 'text/html' }); | 19 | + |
| 18 | - res.end(data); | 20 | + |
| 19 | - }) | 21 | +//css, image 등 정적 파일을 public에서 불러옴 -> html과 연결함 |
| 20 | -}) | 22 | +app.use(express.static(path.join(__dirname, 'public'))); |
| 23 | + | ||
| 24 | + | ||
| 25 | +// app.get('/', (req, res) => { | ||
| 26 | +// //res.send('Server is working'); | ||
| 27 | +// // res.sendFile(path.join(__dirname, '/html/main.html')); | ||
| 28 | +// res.sendFile(__dirname + "/html/main.html"); | ||
| 29 | +// console.log(app.get('port'), '번 포트 대기 중'); | ||
| 30 | +// }); | ||
| 31 | + | ||
| 32 | +// app.get('/login', (req, res) => { | ||
| 33 | +// console.log('로그인 페이지 오픈 시도됨.'); | ||
| 34 | +// res.sendFile(__dirname + "/html/login.html"); | ||
| 35 | +// // fs.readFile('./html/login.html', function (err, data) { | ||
| 36 | +// // res.writeHead(200, { 'Content-Type': 'text/html' }); | ||
| 37 | +// // res.end(data); | ||
| 38 | +// // }) | ||
| 39 | +// }) | ||
| 21 | 40 | ||
| 22 | app.get('/logout', function (req, res) { | 41 | app.get('/logout', function (req, res) { |
| 23 | res.send("Logout success"); | 42 | res.send("Logout success"); | ... | ... |
-
Please register or login to post a comment