import 'reflect-metadata' ; import 'dotenv/config' ; import cors from 'cors' ; import express , { NextFunction , Request , Response } from 'express' ; import 'express-async-errors' ; import '@shared/infra/typeorm' ; import '@shared/container' ; import uploadConfig from '@config/upload' ; import rateLimiter from '@shared/infra/http/middlewares/rateLimiter' ; import AppError from '@shared/errors/AppError' ; import { errors } from 'celebrate' ; import routes from './routes' ; const app = express ( ) ; app . use ( rateLimiter ) ; app . use ( cors ( ) ) ; app . use ( express . json ( ) ) ; app . use ( '/files' , express . static ( uploadConfig . uploadsFolder ) ) ; app . use ( routes ) ; app . use ( errors ( ) ) ; app . use ( ( err , request , response , _ ) => { if ( err instanceof AppError ) { return response . status ( err . statusCode ) . json ( { status : 'error' , message : err . message } ) ; } console . log ( err ) ; return response . status ( 500 ) . json ( { status : 'error' , message : 'Internal server error' , } ) ; } ) ; app . listen ( 3333 , ( ) => { console . log ( '🚀 Server started on port 3333!' ) ; } ) ;