From d1c1fee3634f2d0565efb61786140bbb97d93f55 Mon Sep 17 00:00:00 2001 From: Jonas Verhoelen Date: Tue, 16 Apr 2019 23:11:44 +0200 Subject: [PATCH] some doc + prettier --- .prettierrc | 6 ++++++ package-lock.json | 6 ++++++ package.json | 7 +++++-- service/Application.ts | 6 +++++- service/ExpressServer.ts | 11 ++++++++--- service/index.ts | 6 ++++++ 6 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..09903bc --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "printWidth": 160, + "tabWidth": 4, + "semi": false +} diff --git a/package-lock.json b/package-lock.json index 1d1c3f5..6e9cb34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -364,6 +364,12 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, + "prettier": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", + "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "dev": true + }, "proxy-addr": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", diff --git a/package.json b/package.json index 408c998..bc1fc67 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "npm": ">=6.4.1" }, "scripts": { - "start": "ts-node service/index.ts" + "start": "ts-node service/index.ts", + "prettier:check": "prettier --check service/**/*.{ts,tsx,js,jsx}", + "prettier:write": "prettier --write service/**/*.{ts,tsx,js,jsx}" }, "dependencies": { "express": "^4.16.2" @@ -16,7 +18,8 @@ "devDependencies": { "@types/express": "4.11.1", "typescript": "3.1.1", - "ts-node": "6.1.1" + "ts-node": "6.1.1", + "prettier": "^1.9.2" }, "author": "Jonas Verhoelen ", "repository": { diff --git a/service/Application.ts b/service/Application.ts index da1d587..3a1d880 100644 --- a/service/Application.ts +++ b/service/Application.ts @@ -1,5 +1,9 @@ import { ExpressServer } from './ExpressServer' +/** + * Wrapper around the Node process, ExpressServer abstraction and complex dependencies such as services that ExpressServer needs. + * When not using Dependency Injection, can be used as place for wiring together services which are dependencies of ExpressServer. + */ export class Application { public static async createApplication() { const expressServer = new ExpressServer() @@ -43,4 +47,4 @@ export class Application { process.exit(1) }) } -} \ No newline at end of file +} diff --git a/service/ExpressServer.ts b/service/ExpressServer.ts index 9ab2f31..d2cf3e1 100644 --- a/service/ExpressServer.ts +++ b/service/ExpressServer.ts @@ -1,7 +1,12 @@ import * as express from 'express' -import { Express} from 'express' +import { Express } from 'express' import { Server } from 'http' +/** + * Abstraction around the raw Express.js server and Nodes' HTTP server. + * Defines HTTP request mappings, basic as well as request-mapping-specific + * middleware chains for application logic, config and everything else. + */ export class ExpressServer { private server?: Express private httpServer?: Server @@ -13,11 +18,11 @@ export class ExpressServer { return this.server } - public listen(server: Express, port: number) { + public listen(server: Express, port: number) { return server.listen(port) } public kill() { if (this.httpServer) this.httpServer.close() } -} \ No newline at end of file +} diff --git a/service/index.ts b/service/index.ts index d6ee6ea..791ecd4 100644 --- a/service/index.ts +++ b/service/index.ts @@ -1,5 +1,11 @@ import { Application } from './Application' +/** + * Entrypoint for bootstrapping and starting the application. + * Might configure aspects like logging, telemetry, memory leak observation or even orchestration before. + * This is about to come later! + */ + Application.createApplication().then(() => { console.info('The application was started! Kill it using Ctrl + C') })