refactor - example - moved app related logic to separated file
ADD
example/app.ts
+import { bodyParser$, httpListener, logger$ } from '../src';
+import { hello$, root$ } from './controllers';
+
+const middlewares = [
+ logger$,
+ bodyParser$,
+];
+
+const effects = [
+ root$,
+ hello$,
+];
+
+export const app = httpListener({ middlewares, effects });

MODIFY
example/index.ts
example/index.ts
import * as http from 'http';
-import { root$, hello$ } from './controllers';
-import { httpListener, logger$, bodyParser$ } from '../src';
+import { app } from './app';
-const createServer = () => {
+const createServer = app => {
const HOSTNAME = '127.0.0.1';
const PORT = 1337;
- const middlewares = [
- logger$,
- bodyParser$,
- ];
-
- const effects = [
- root$,
- hello$,
- ];
-
- const app = httpListener({ middlewares, effects });
-
const httpServer = http
.createServer(app)
.listen(PORT, HOSTNAME, () => {
@@ -29,4 +16,4 @@ const createServer = () => {
});
};
-createServer();
+createServer(app);

MODIFY
src/middlewares/index.ts
src/middlewares/index.ts
export * from './bodyParser.middleware';
export * from './logger.middleware';
+export * from './errorCatcher.middleware';

refactor - example - moved app related logic to separated file