refactor: moved middlewares in dedicated file
This commit is contained in:
parent
8c812812df
commit
85cf0e6d13
|
@ -1,8 +1,6 @@
|
|||
import http from 'http'
|
||||
|
||||
import express, { Application } from 'express'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import logger from 'morgan'
|
||||
import initDebug from 'debug'
|
||||
|
||||
import indexRouter from './routes'
|
||||
|
@ -10,7 +8,7 @@ import usersRouter from './routes/users'
|
|||
|
||||
import { normalizePort } from './helpers/port'
|
||||
import { getErrorCb, getListeningCb } from './helpers/server-callbacks'
|
||||
import { WEBUI_DIR } from './helpers/paths'
|
||||
import { registerMiddlewares } from './middlewares'
|
||||
|
||||
const PORT = normalizePort(process.env.PORT || '6595')
|
||||
|
||||
|
@ -19,17 +17,13 @@ const app: Application = express()
|
|||
const server = http.createServer(app)
|
||||
|
||||
/* === Middlewares === */
|
||||
app.use(logger('dev'))
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: false }))
|
||||
app.use(cookieParser())
|
||||
app.use(express.static(WEBUI_DIR))
|
||||
registerMiddlewares(app)
|
||||
|
||||
/* === Routes === */
|
||||
app.use('/', indexRouter)
|
||||
app.use('/users', usersRouter)
|
||||
|
||||
/* === Other === */
|
||||
/* === Config === */
|
||||
app.set('port', PORT)
|
||||
|
||||
/* === Server port === */
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import type { Application } from 'express'
|
||||
import logger from 'morgan'
|
||||
import express from 'express'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import { WEBUI_DIR } from './helpers/paths'
|
||||
|
||||
export function registerMiddlewares (app: Application) {
|
||||
app.use(logger('dev'))
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: false }))
|
||||
app.use(cookieParser())
|
||||
app.use(express.static(WEBUI_DIR))
|
||||
}
|
Loading…
Reference in New Issue