import express , { RequestHandler } from 'express' ; import methodOverride from 'method-override' ; import bodyParser from 'body-parser' ; import './rootController.js' ; import { RegisterRoutes } from './routes.js' ; export const app = express ( ) ; app . use ( bodyParser . urlencoded ( { extended : true } ) as RequestHandler ) ; app . use ( bodyParser . json ( ) as RequestHandler ) ; app . use ( methodOverride ( ) ) ; app . use ( ( req , res , next ) => { req . stringValue = 'fancyStringForContext' ; next ( ) ; } ) ; RegisterRoutes ( app ) ; app . use ( ( err , req , res , next ) => { const status = err . status || 500 ; const body = { fields : err . fields || undefined , message : err . message || 'An error occurred during the request.' , name : err . name , status , } ; res . status ( status ) . json ( body ) ; } ) ; app . listen ( ) ;