()
| 31 | } |
| 32 | |
| 33 | async function bootstrap() { |
| 34 | const logger = new Logger('SERVER'); |
| 35 | const app = express(); |
| 36 | |
| 37 | let providerFiles: ProviderFiles = null; |
| 38 | if (configService.get<ProviderSession>('PROVIDER').ENABLED) { |
| 39 | providerFiles = new ProviderFiles(configService); |
| 40 | await providerFiles.onModuleInit(); |
| 41 | logger.info('Provider:Files - ON'); |
| 42 | } |
| 43 | |
| 44 | const prismaRepository = new PrismaRepository(configService); |
| 45 | await prismaRepository.onModuleInit(); |
| 46 | |
| 47 | app.use( |
| 48 | cors({ |
| 49 | origin(requestOrigin, callback) { |
| 50 | const { ORIGIN } = configService.get<Cors>('CORS'); |
| 51 | if (ORIGIN.includes('*')) { |
| 52 | return callback(null, true); |
| 53 | } |
| 54 | if (ORIGIN.indexOf(requestOrigin) !== -1) { |
| 55 | return callback(null, true); |
| 56 | } |
| 57 | return callback(new Error('Not allowed by CORS')); |
| 58 | }, |
| 59 | methods: [...configService.get<Cors>('CORS').METHODS], |
| 60 | credentials: configService.get<Cors>('CORS').CREDENTIALS, |
| 61 | }), |
| 62 | urlencoded({ extended: true, limit: '136mb' }), |
| 63 | json({ limit: '136mb' }), |
| 64 | compression(), |
| 65 | ); |
| 66 | |
| 67 | app.set('view engine', 'hbs'); |
| 68 | app.set('views', join(ROOT_DIR, 'views')); |
| 69 | app.use(express.static(join(ROOT_DIR, 'public'))); |
| 70 | |
| 71 | app.use('/store', express.static(join(ROOT_DIR, 'store'))); |
| 72 | |
| 73 | app.use('/', router); |
| 74 | |
| 75 | app.use( |
| 76 | (err: Error, req: Request, res: Response, next: NextFunction) => { |
| 77 | if (err) { |
| 78 | const webhook = configService.get<Webhook>('WEBHOOK'); |
| 79 | |
| 80 | if (webhook.EVENTS.ERRORS_WEBHOOK && webhook.EVENTS.ERRORS_WEBHOOK != '' && webhook.EVENTS.ERRORS) { |
| 81 | const tzoffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds |
| 82 | const localISOTime = new Date(Date.now() - tzoffset).toISOString(); |
| 83 | const now = localISOTime; |
| 84 | const globalApiKey = configService.get<Auth>('AUTHENTICATION').API_KEY.KEY; |
| 85 | const serverUrl = configService.get<HttpServer>('SERVER').URL; |
| 86 | |
| 87 | const errorData = { |
| 88 | event: 'error', |
| 89 | data: { |
| 90 | error: err['error'] || 'Internal Server Error', |
no test coverage detected