-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
51 lines (38 loc) · 1.21 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Imports from libraries
import express, { Application } from 'express';
import morgan from 'morgan';
import cors from 'cors';
import path from 'path';
// Imports from project
import globalErrorHandler from './controllers/error/errorController';
import viewsRouter from './routes/viewsRoutes';
import charityRouter from './routes/charityRoutes';
import fundRaiserRouter from './routes/fundRaisingRoutes';
import AppError from './utils/appError';
const app: Application = express();
// -----------------------------------
// MIDDLEWARE STACK
// Development middlewares
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
// CORS middleware
app.use(cors());
// Req body modifiers
app.use(express.json());
// Views middleware
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
// -----------------------------------
// ROUTERS
app.use('/charity', charityRouter);
app.use('/fund-raiser', fundRaiserRouter);
app.use('/', viewsRouter);
app.get('/charityPost',function(req,res){
res.render("charityPost");
});
app.all('*', (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server`, 404));
});
app.use(globalErrorHandler);
export default app;