Skip to content

Commit

Permalink
some doc + prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Verhoelen committed Apr 16, 2019
1 parent bd7c15f commit d1c1fee
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"printWidth": 160,
"tabWidth": 4,
"semi": false
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
"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"
},
"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 <[email protected]>",
"repository": {
Expand Down
6 changes: 5 additions & 1 deletion service/Application.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -43,4 +47,4 @@ export class Application {
process.exit(1)
})
}
}
}
11 changes: 8 additions & 3 deletions service/ExpressServer.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
}
}
6 changes: 6 additions & 0 deletions service/index.ts
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit d1c1fee

Please sign in to comment.