-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (30 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
// Import necessary External modules
import express from 'express';
import ejsLayouts from 'express-ejs-layouts';
// Import necessary Core modules
import path from 'path';
// Import necessary Internal modules
import homeRouter from './src/routers/home.routes.js';
import habitsRouter from './src/routers/habit.routes.js';
import progressRouter from './src/routers/progress.routes.js';
import handleInvalidRoute from './src/middlewares/handleInvalidRoute.middleware.js';
import handleApplicationLevelErrors from './src/middlewares/handleApplicationLevelErrors.middleware.js';
// Initialize the Express application
const app = express();
app.set('view engine', 'ejs'); // Set EJS as view-engine
app.set('views', path.join(path.resolve(), 'src', 'views')); // Set views path
app.set('layout', './layouts/main'); // Set the default layout for the application
app.use(ejsLayouts); // Use EJS layouts for redering views with layouts
app.use(express.static(path.join(path.resolve(), 'public')));
app.use(express.json()); // Parse incomming json requests
// Mount Home Router to handle home related requests
app.use('/', homeRouter);
// Mount Habits Router to handle habits related requests
app.use('/habits', habitsRouter);
// Mount Progress Router to handle progress related requests
app.use('/progress', progressRouter);
// Handle invalid routes
app.use(handleInvalidRoute);
// Handle all application errors
app.use(handleApplicationLevelErrors);
export default app;