Skip to content

Commit

Permalink
Refactor: remaining default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
phr3nzy committed Sep 11, 2019
1 parent d5773b6 commit 2a6f587
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import http from 'http';
import express from 'express';
import { applyMiddleware, applyRoutes } from './utils';
import { middlewareHandler } from './middleware';
import errorHandlers from './middleware/errorHandler';
import { errorHandlers } from './middleware/errorHandler';
import { routeHandler } from './routes';
import chalk from 'chalk';
import consola from 'consola';
Expand Down
4 changes: 3 additions & 1 deletion lib/middleware/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ const handleServerError: (router: Router) => void = (router: Router) => {
});
};

export default [handle404Error, handle401Error, handleClientError, handleServerError];
const errorHandlers = [handle404Error, handle401Error, handleClientError, handleServerError];

export { errorHandlers };
10 changes: 3 additions & 7 deletions lib/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import mainRoutes from './main/index';
import userRoutes from './users/index';
import { mainRoutes } from './main/index';
import { userRoutes } from './users/index';

const routeHandler = [...mainRoutes, ...userRoutes];

export { routeHandler };

// export default [...mainRoutes, ...userRoutes];
export const routeHandler = [...mainRoutes, ...userRoutes];
2 changes: 1 addition & 1 deletion lib/routes/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response } from 'express';
import { API_VER } from '../../config/index';

export default [
export const mainRoutes = [
{
handler: async (req: Request, res: Response) => {
res.send('Node Backend API');
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express';
import { authenticateUser, newUser } from '../../controllers/users';
import { authUserCheck, newUserCheck } from '../../middleware/checks/users';

export default [
export const userRoutes = [
{
handler: [
newUserCheck,
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HTTP400Error, HTTP401Error, HTTP404Error } from '../utils/httpErrors';
import express, { Router } from 'express';
import { applyMiddleware } from '../utils';
import errorHandlers from '../middleware/errorHandler';
import { errorHandlers } from '../middleware/errorHandler';

describe('errors', () => {
test('throws http 400 error', async done => {
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import express, { Router } from 'express';
import request from 'supertest';
import { applyMiddleware, applyRoutes } from '../utils';
import { middlewareHandler } from '../middleware';
import errorHandlers from '../middleware/errorHandler';
import routes from '../routes/main';
import { errorHandlers } from '../middleware/errorHandler';
import { mainRoutes } from '../routes/main';
import mongoose from 'mongoose';

const status200 = 200;
Expand All @@ -15,7 +15,7 @@ describe('routes', () => {
beforeEach(() => {
router = express();
applyMiddleware(middlewareHandler, router);
applyRoutes(routes, router);
applyRoutes(mainRoutes, router);
applyMiddleware(errorHandlers, router);
});

Expand Down

0 comments on commit 2a6f587

Please sign in to comment.