first
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import createError from 'http-errors'
|
||||
import logger from 'morgan'
|
||||
import express from 'express'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import cors from 'cors'
|
||||
|
||||
import indexRouter from './routes/index.js'
|
||||
import apiRouter from './routes/index.js'
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use(cors())
|
||||
app.use(logger('dev'))
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
app.use(cookieParser())
|
||||
|
||||
app.use('/api', apiRouter)
|
||||
app.use('/', indexRouter)
|
||||
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
next(createError(404))
|
||||
})
|
||||
|
||||
// error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
||||
|
||||
// render the error page
|
||||
res.status(err.status || 500)
|
||||
res.send(`ERROR: ${err.status}, ${err.stack}`)
|
||||
})
|
||||
|
||||
export default app
|
||||
Reference in New Issue
Block a user