-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
55 lines (40 loc) · 1.42 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
const express = require('express');
const cookieParser = require('cookie-parser');
const monogoSanitize = require('express-mongo-sanitize');
const morgan = require('morgan');
const connectDB = require('./src/db/db');
// App logic based routes
const userRoute = require('./src/routes/userRoute');
const groupRoute = require('./src/routes/groupRoute');
const journalRoute = require('./src/routes/journalRoutes');
const handlePaymentRoute = require('./src/routes/journalRoutes');
const settlementRoutes = require('./src/settlements/setRoutes/settleRoute');
// Initialize the app
const app = express();
// Connect to the database
connectDB();
// Middleware to parse JSON and urlEncoded
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(monogoSanitize());
// Cookie parser middleware
app.use(cookieParser());
// HTTP request logger middleware
app.use(morgan('tiny'));
// Sample route to test the server
app.get('/home', (req, res) => {
res.status(200).json({
message: 'hello visitor!',
});
});
// User route middleware
app.use('api/v1/user/new', userRoute);
// Group create and join route middleware
app.use('api/v1/handle/gcreate', groupRoute);
// expense journal routes and middlewares
app.use('api/v1/expenses', journalRoute);
// payments routes for settlements
app.use('api/v1/pay', handlePaymentRoute);
// setllemtn route
app.use('/api/v1/settlements', settlementRoutes);
module.exports = app;