-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
46 lines (40 loc) · 1.28 KB
/
app.js
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
const express = require('express')
const bodyParser = require('body-parser')
const fs = require('fs')
const session = require('express-session')
const path = require('path')
const morgan = require('morgan')
const logger = require('./logger')
require('dotenv').config()
const app=express()
app.use(morgan('combined'))
app.use('/static',express.static(path.join(__dirname,'/static')))
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use( (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH')
res.header('Access-Control-Allow-Headers', 'content-type, x-access-token')
next()
})
app.use(session({
secret:'ambc@!vsmkv#!&*!#EDNAnsv#!$()_*#@',
resave:false,
saveUninitialized:true
}))
app.use('/api',require('./api'))
app.get('/',(req,res)=>{
if(!req.session.verified){
res.redirect('/views/auth')
}
else{
res.redirect('/views/list')
}
})
app.use('/views',require('./views'))
app.use((req,res,next)=>{
res.status(404).send("페이지를 찾을 수 없습니다.\n" +"개발자에게 문의해주세요!")
})
app.listen(process.env.SERVER_PORT ||3000,()=>{
console.log('server is running on port '+process.env.SERVER_PORT)
})