-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (26 loc) · 911 Bytes
/
app.js
File metadata and controls
32 lines (26 loc) · 911 Bytes
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
const express = require('express');
const morgan = require('morgan');
const userRouter = require('./routes/userRoutes');
const problemRouter = require('./routes/problemRoutes');
const submissionRouter = require('./routes/submissionRoutes');
const AppError = require('./utils/appError');
const globalErrorHandler = require('./controllers/errorController');
// Creating the express app
const app = express();
// Third party middlewares
app.use(morgan('dev'));
app.use(express.json());
// Setting up routes
app.use('/v1/users', userRouter);
app.use('/v1/submission', submissionRouter);
app.use('/v1/problem', problemRouter);
app.get('/v1', (req, res) => {
res.json({ des: 'CodeHub Homepage' });
//next();
});
app.all('*', (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
app.use(globalErrorHandler);
// Exporting the express app
module.exports = app;