Skip to content

Commit 2154e33

Browse files
committed
prepare for tests
1 parent 3ca8e06 commit 2154e33

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

src/app.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import express, { Request, Response, NextFunction } from 'express';
2+
import Logger from './utils/Logger';
3+
import bodyParser from 'body-parser';
4+
import cors from 'cors';
5+
import { corsUrl, environment } from './config';
6+
import './database'; // initialize database
7+
import { NotFoundError, ApiError, InternalError } from './utils/ApiError';
8+
9+
const app = express();
10+
11+
app.use(bodyParser.json({ limit: '10mb' }));
12+
app.use(bodyParser.urlencoded({ limit: '10mb', extended: true, parameterLimit: 50000 }));
13+
app.use(cors({ origin: corsUrl, optionsSuccessStatus: 200 }));
14+
15+
// Routes
16+
app.use('/v1', require('./routes/v1'));
17+
18+
// catch 404 and forward to error handler
19+
app.use((req, res, next) => next(new NotFoundError()));
20+
21+
// Middleware Error Handler
22+
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
23+
if (err instanceof ApiError) {
24+
ApiError.handle(err, res);
25+
} else {
26+
if (environment === 'development') {
27+
Logger.error(err);
28+
return res.status(500).send(err.message);
29+
}
30+
ApiError.handle(new InternalError(), res);
31+
}
32+
});
33+
34+
export default app;

src/server.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
import express, { Request, Response, NextFunction } from 'express';
21
import Logger from './utils/Logger';
3-
import bodyParser from 'body-parser';
4-
import http from 'http';
5-
import cors from 'cors';
6-
import { port, corsUrl, environment } from './config';
7-
import './database'; // initialize database
8-
import { NotFoundError, ApiError, InternalError } from './utils/ApiError';
2+
import { port } from './config';
3+
import app from './app';
94

10-
const app = express();
11-
12-
app.use(bodyParser.json({ limit: '10mb' }));
13-
app.use(bodyParser.urlencoded({ limit: '10mb', extended: true, parameterLimit: 50000 }));
14-
app.use(cors({ origin: corsUrl, optionsSuccessStatus: 200 }));
15-
16-
http.createServer(app).listen(port, () => { Logger.info(`server running on port : ${port}`); });
17-
18-
// Routes
19-
app.use('/v1', require('./routes/v1'));
20-
21-
// catch 404 and forward to error handler
22-
app.use((req, res, next) => next(new NotFoundError()));
23-
24-
// Middleware Error Handler
25-
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
26-
if (err instanceof ApiError) {
27-
ApiError.handle(err, res);
28-
} else {
29-
if (environment === 'development') {
30-
Logger.error(err);
31-
return res.status(500).send(err.message);
32-
}
33-
ApiError.handle(new InternalError(), res);
34-
}
35-
});
5+
app.listen(port, () => { Logger.info(`server running on port : ${port}`); });

src/utils/logger.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ export default createLogger({
3838
level: logLevel,
3939
format: format.combine(
4040
format.colorize(),
41-
format.metadata(),
4241
format.errors({ stack: true }),
43-
format.prettyPrint())
42+
format.simple())
4443
}),
4544
],
4645
exceptionHandlers: [

test/auth/apikey.test.ts

Whitespace-only changes.

test/utils/ApiResponse.test.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)