-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (41 loc) · 1.32 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
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import morgan from 'morgan';
import swaggerUi from 'swagger-ui-express';
import 'dotenv/config';
import codes from './helpers/statusCode';
import swaggerDoc from './swagger.json';
import {
officeRoutes, partyRoutes, authRoutes, userRoutes,
candidateRoutes, voteRoutes, otherRoutes,
} from './routes';
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.get('/', (req, res) => res.status(codes.success).send({
status: codes.success,
data: {
message: 'The app is running',
},
}));
app.use('/api/v1/parties', partyRoutes);
app.use('/api/v1/offices', officeRoutes);
app.use('/api/v1/users', userRoutes);
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/votes', voteRoutes);
app.use('/api/v1/candidates', candidateRoutes);
app.use('/api/v1', otherRoutes);
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));
app.get('*', (req, res) => res.status(codes.notFound).send({
status: codes.notFound,
error: 'Page not found.',
}));
app.listen(PORT);
// eslint-disable-next-line no-console
console.log('app running on port ', PORT);
export default app;