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
|
import express from 'express'
import * as path from 'path'
import cors from 'cors'
import cookieSession from 'cookie-session'
import { connect } from './libraries/Database'
import Session from './middlewares/Session'
import flash from 'express-flash'
import routes from './Controllers'
import config from './config.json'
class App {
public app: express.Application
constructor() {
this.app = express()
this.config()
}
private async config() {
this.app.set('config', config)
this.app.set('DB', await connect(config.mysql))
this.app.set('views', path.join(__dirname, 'views'))
this.app.set('view engine', 'ejs')
this.app.use(express.static(path.join(__dirname, 'public')))
this.app.use(express.urlencoded({ extended: true }))
this.app.use(cors())
this.app.use(
cookieSession({
httpOnly: true,
keys: ['key1', 'key2'],
maxAge: 10 * 60 * 1000,
name: 'session',
})
)
this.app.use(Session)
this.app.use(flash())
this.app.use('/', routes)
}
}
export default new App().app |
Partager