-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
60 lines (46 loc) · 1.57 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
57
58
59
60
const express = require('express');
const app = express();
require('dotenv').config();
const path = require('path');
const cors = require('cors');
const server = require('http').createServer(app);
const port = process.env.PORT || 3000;
const AppModule = require('./app/modules/index');
const indexRoute = require('./routes/index');
const {
AuthModule, CategoryModule, BalanceModule, ExpenseModule, MealModule, MessModule, UserModule,
} = AppModule;
const { UserRoute } = UserModule;
const { CategoryRoute } = CategoryModule;
const { BalanceRoute } = BalanceModule;
const { ExpenseRoute } = ExpenseModule;
const { MealRoute } = MealModule;
const { MessRoute } = MessModule;
const { AuthController, AuthRoute } = AuthModule;
const authController = new AuthController();
require('./config/database')();
const corsOptions = {
origin: true,
methods: 'GET,HEAD,PUT,POST,DELETE',
credentials: true,
exposedHeaders: ['x-auth-token'],
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({
extended: true,
}));
// Root Routing
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRoute);
app.use('/api/auth', AuthRoute);
app.all('/api/v1/*', authController.isAuthenticate);
app.use('/api/v1/user', UserRoute);
app.use('/api/v1/category', CategoryRoute);
app.use('/api/v1/balance', BalanceRoute);
app.use('/api/v1/expense', ExpenseRoute);
app.use('/api/v1/meal', MealRoute);
app.use('/api/v1/mess', MessRoute);
server.listen(port, () => {
console.log(`Server is running on ${process.env.HOST}:${process.env.PORT}`);
});