import * as express from "express" ; import { json , urlencoded } from "body-parser" ; import * as http from "http" ; import * as path from "path" ; import { PostRouter } from "./routes/post/post" ; import { AuthorRouter } from "./routes/author/author" ; import { APIDocsRouter } from "./routes/swagger" ; const app = express ( ) ; app . use ( json ( ) ) ; app . use ( urlencoded ( { extended : true } ) ) ; app . get ( "/" , ( request , response ) => { response . json ( { name : "Express application" } ) ; } ) ; app . use ( ( err , request , response , next ) : void => { response . status ( err . status || 500 ) ; response . json ( { error : "Server error" } ) ; } ) ; app . use ( "/api" , PostRouter . routes ( ) ) ; app . use ( "/api" , new AuthorRouter ( ) . getRouter ( ) ) ; app . use ( "/api/swagger" , new APIDocsRouter ( ) . getRouter ( ) ) ; app . use ( "/docs" , express . static ( path . join ( __dirname , './assets/swagger' ) ) ) ; const server = app . listen ( process . env . PORT || 3000 ) ; export { server } ;