-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (41 loc) · 1.44 KB
/
app.js
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
52
53
54
55
56
// app.js
import cookieParser from 'cookie-parser';
import express from 'express';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import dotenv from 'dotenv';
// import cors from 'cors';
// import helmet from 'helmet';
import rateLimit from 'express-rate-limit';
import morgan from "morgan";
import config from './config/config.js';
import authRouter from './src/routes/authRoutes.js';
import blogRouter from './src/routes/blogRoutes.js';
import profileRouter from './src/routes/profileRoutes.js';
// import docRouter from './src/routes/docRoutes.js';
import { errorHandler } from './src/middleware/errorHandler.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config();
const app = express();
// Security middleware
// app.use(helmet(config.security.helmet));
// app.use(cors(config.security.cors));
app.use(express.json({ limit: '2MB' }));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(rateLimit(config.security.rateLimit));
app.use(morgan('dev')); // Logs HTTP requests
// Serve static files from the public directory
app.use(express.static('./src/public'));
// Set view engine to EJS
app.set('views', join(__dirname, 'src', 'views'));
app.set('view engine', 'ejs');
// Routes
app.use( authRouter );
app.use( blogRouter );
app.use(profileRouter);
// app.use(docRouter);
// Global middlewares
app.use(errorHandler);
export default app;