2021-04-03 17:46:54 +00:00
|
|
|
import type { Application } from 'express'
|
|
|
|
import express from 'express'
|
2021-05-13 18:47:48 +00:00
|
|
|
import logger from 'morgan'
|
2021-04-03 17:46:54 +00:00
|
|
|
import cookieParser from 'cookie-parser'
|
2021-05-03 15:08:36 +00:00
|
|
|
import session from 'express-session'
|
|
|
|
|
2021-05-11 18:21:37 +00:00
|
|
|
import { WEBUI_DIR } from './helpers/paths'
|
|
|
|
|
2021-05-03 15:08:36 +00:00
|
|
|
declare module 'express-session' {
|
2021-05-11 18:21:37 +00:00
|
|
|
export interface SessionData {
|
|
|
|
dz: any
|
|
|
|
}
|
2021-05-03 15:08:36 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 17:46:54 +00:00
|
|
|
export function registerMiddlewares(app: Application) {
|
2021-04-24 16:03:27 +00:00
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
app.use(logger('dev'))
|
|
|
|
}
|
|
|
|
|
2021-04-03 17:46:54 +00:00
|
|
|
app.use(express.json())
|
|
|
|
app.use(express.urlencoded({ extended: false }))
|
|
|
|
app.use(cookieParser())
|
2021-05-11 18:21:37 +00:00
|
|
|
app.use(
|
|
|
|
session({
|
|
|
|
secret: 'U2hoLCBpdHMgYSBzZWNyZXQh',
|
|
|
|
resave: true,
|
|
|
|
saveUninitialized: true
|
|
|
|
})
|
|
|
|
)
|
2021-04-03 17:46:54 +00:00
|
|
|
app.use(express.static(WEBUI_DIR))
|
|
|
|
}
|