-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.ts
37 lines (30 loc) · 946 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import express, { Application, Response, Request, NextFunction } from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import routes from './routes';
import { walletCheck } from './services/wallet';
import { responseError } from './helpers';
import { cron } from './services/cron';
const app: Application = express();
// App middlewares
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Router files
app.use('/', routes);
// Base error handler
app.use((err: Error, req: Request, res: Response, next: NextFunction): void => {
if (err) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
responseError(res, 500, err.message);
}
});
try {
walletCheck();
cron();
} catch (err) {
// Log error
console.log('App Error ===', (err as Error).message);
}
export default app;