Skip to content

Commit 8e760e7

Browse files
author
hirsch88
committed
Add monitoring, update readme and house cleaning
1 parent 9a36d5a commit 8e760e7

File tree

18 files changed

+673
-681
lines changed

18 files changed

+673
-681
lines changed

.vscode/launch.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Launch App",
11-
"stopOnEntry": true,
12-
"program": "${workspaceRoot}/src/index.ts",
13-
"cwd": "${workspaceRoot}",
14-
"sourceMaps": true,
10+
"name": "Debug",
11+
"program": "${workspaceRoot}/dist/index.js",
12+
"smartStep": true,
13+
"outFiles": [
14+
"../dist/**/*.js"
15+
],
16+
"protocol": "inspector",
1517
"preLaunchTask": "build",
1618
"env": {
1719
"NODE_ENV": "development"

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
22
"typescript.tsdk": "./node_modules/typescript/lib",
3-
"files.exclude": {
4-
"src/**/*.js": false,
5-
"test/**/*.js": true
6-
},
7-
"vsicons.presets.angular": false,
83
"cSpell.enabled": true
94
}

.vscode/tasks.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
"args": [
2323
"test"
2424
]
25-
},
26-
{
27-
// "npm run lint"
28-
"taskName": "lint",
29-
"args": [
30-
"run",
31-
"lint"
32-
]
33-
},
34-
{
35-
// "npm run clean"
36-
"taskName": "clean",
37-
"args": [
38-
"run",
39-
"clean"
40-
]
4125
}
4226
]
4327
}

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Express Typescript Boilerplate [![Build Status](https://travis-ci.org/w3tecch/express-typescript-boilerplate.svg?branch=master)](https://travis-ci.org/w3tecch/express-typescript-boilerplate)
1+
# Express Typescript Boilerplate
2+
[![Dependency Status](https://david-dm.org/w3tecch/express-typescript-boilerplate/status.svg?style=flat)](https://david-dm.org/w3tecch/express-typescript-boilerplate) [![Build Status](https://travis-ci.org/w3tecch/express-typescript-boilerplate.svg?branch=master)](https://travis-ci.org/w3tecch/express-typescript-boilerplate)
23

34
A delightful way to building a RESTful API with NodeJs & TypeScript.
45
- **Beautiful Syntax** thanks to the awesome annotations from [Inversify Express Utils](https://github.com/inversify/inversify-express-utils).
@@ -12,6 +13,8 @@ A delightful way to building a RESTful API with NodeJs & TypeScript.
1213
- **Custom Commands** are also available in our setup and really easy to use.
1314
- **Smart Validation** thanks to [class-validator](https://github.com/pleerock/class-validator) with some nice annotations.
1415
- **API Documentation** thanks to [swagger](http://swagger.io/).
16+
- **API Monitoring** thanks to [express-status-monitor](https://github.com/RafalWilinski/express-status-monitor).
17+
- **Integrated Testing Tool** thanks to [Wallaby.js](https://wallabyjs.com/)
1518

1619
## Getting Started
1720
### Prerequisites
@@ -20,7 +23,7 @@ A delightful way to building a RESTful API with NodeJs & TypeScript.
2023
* on Windows use [chocolatey](https://chocolatey.org/) `choco install nodejs`
2124
* Install yarn globally `npm install yarn -g`
2225

23-
## Installing
26+
### Installing
2427
* `fork` this repo
2528
* `clone` your fork
2629
* `yarn install` to install all dependencies and typings
@@ -29,12 +32,14 @@ A delightful way to building a RESTful API with NodeJs & TypeScript.
2932
* `npm run db:seed` to insert some test data
3033
* `npm run serve` to start the dev server in another tab
3134

32-
## Running the app
35+
### Running the app
3336
After you have installed all dependencies you can now run the app.
3437
Run `npm run serve` to start a local server using `nodemon` which will watch for changes and then will restart the sever.
3538
The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv6, if you're using `express` server, then it's `http://[::1]:3000/`).
3639

37-
## Scripts / Commands
40+
## Scripts / Tasks
41+
All script are defined in the package.json file, but the most important ones are listed here.
42+
3843
### Install
3944
* Install all dependencies with `yarn install`
4045

@@ -51,9 +56,6 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
5156
* Run `npm run serve` to start nodemon with ts-node, which will serve your app.
5257
* The server address will be displayed to you as `http://0.0.0.0:3000`
5358

54-
### Cleaning the project
55-
* Run `npm run clean` to remove all generated JavaScript files.
56-
5759
### Building the project and run it
5860
* Run `npm run build` to generated all JavaScript files from your TypeScript sources. After this step you can deploy the app on any server.
5961
* There is also a vscode task for this called build.
@@ -68,7 +70,51 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
6870
### Console
6971
* To run your own created cli script enter `npm run console <command-name>`
7072

73+
## Using the debugger in VS Code
74+
Just set a breakpoint and hit `F5` in your Visual Studio Code.
75+
76+
## API Routes
77+
The route prefix is by default `/api/v1`, but you can change this in the .env.example file.
78+
79+
| Route | Description |
80+
| ----------- | ----------- |
81+
| **/info** | Shows us the name, description and the version of the package.json |
82+
| **/docs** | This is the Swagger UI with our API Documentation |
83+
| **/status** | Shows a small monitor app for our API |
84+
85+
## Project Structure
86+
87+
| Name | Description |
88+
| ----------------------------- | ----------- |
89+
| **.vscode/** | VSCode tasks, launch configuration and some other settings |
90+
| **build/** | Task Runner configurations and tasks |
91+
| **dist/** | Compiled source files will be placed here |
92+
| **src/** | Source-Files |
93+
| **src/api/controllers/** | REST-API - Controllers |
94+
| **src/api/exceptions/** | Exceptions like 404 NotFound |
95+
| **src/api/middlewares/** | Express Middlewares like populateUser |
96+
| **src/api/models/** | Bookshelf Models |
97+
| **src/api/repositories/** | Repository Layer |
98+
| **src/api/requests/** | Request Bodys with Validations |
99+
| **src/api/services/** | Service Layer |
100+
| **src/api/** swagger.json | Swagger Documentation |
101+
| **src/console/** | Command Line scripts |
102+
| **src/constants/** | Global Constants |
103+
| **src/core/** | All the libraries configurations and our small framework |
104+
| **src/database/factories/** | Model Factories to generate database records |
105+
| **src/database/migrations/** | Migrations scripts to build up our database schema |
106+
| **src/database/seeds/** | Seed scripts to fake some data into our database |
107+
| **src/public/** | Static assets (fonts, css, js, img). |
108+
| **src/types/** *.d.ts | Custom Type Definitions and files that aren't on DefinitelyTyped |
109+
| **test** | All our test cases |
110+
| **test/setup/** | Some setup scripts to create a needed test environment |
111+
| **test/black-box/** *.test.ts | Black-Box Testing (like e2e) |
112+
| **test/unit/** *.test.t | Unit Testing |
113+
| .env.example | All environment configurations |
114+
| knexfile.ts | This file is used for the migrations and seed task of knex |
115+
71116
## Related Projects
117+
* [Microsoft/TypeScript-Node-Starter](https://github.com/Microsoft/TypeScript-Node-Starter) - A starter template for TypeScript and Node with a detailed README describing how to use the two together.
72118
* [express-graphql-typescript-boilerplate](https://github.com/w3tecch/express-graphql-typescript-boilerplate) - A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
73119
* [aurelia-typescript-boilerplate](https://github.com/w3tecch/aurelia-typescript-boilerplate) - An Aurelia starter kit with TypeScript
74120
* [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server)

build/tasks/build.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

build/tasks/clean-dist.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const gulp = require('gulp');
4+
const path = require('path');
5+
const paths = require('../paths');
6+
const $ = require('gulp-load-plugins')({
7+
lazy: true
8+
});
9+
10+
11+
gulp.task('clean:dist', () => {
12+
return gulp
13+
.src(paths.dist, {
14+
read: false
15+
})
16+
.pipe($.clean());
17+
});

build/tasks/clean.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

build/tasks/copy-assets.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const gulp = require('gulp');
4+
const path = require('path');
5+
const paths = require('../paths');
6+
const $ = require('gulp-load-plugins')({
7+
lazy: true
8+
});
9+
10+
11+
gulp.task('copy:assets', () => {
12+
return gulp
13+
.src([
14+
path.join(paths.src, '/public/**/*'),
15+
path.join(paths.src, '/**/*.json')
16+
], { base: paths.src })
17+
.pipe(gulp.dest(paths.dist));
18+
});

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/index.ts",
66
"scripts": {
7-
"lint": "./node_modules/.bin/tslint -c ./tslint.json 'src/**/*.ts' --format stylish --force",
87
"test": "NODE_ENV=test ./node_modules/.bin/jest ./test/unit",
98
"test:pretty": "NODE_ENV=test ./node_modules/.bin/jest ./test/unit --verbose",
109
"test:coverage": "NODE_ENV=test ./node_modules/.bin/jest ./test/unit --coverage",
1110
"test:black-box": "NODE_ENV=test ./node_modules/.bin/jest ./test/black-box -i",
1211
"test:black-box:pretty": "NODE_ENV=test ./node_modules/.bin/jest ./test/black-box -i --verbose",
13-
"build": "./node_modules/.bin/gulp build",
14-
"clean": "./node_modules/.bin/gulp clean",
12+
"lint": "./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish",
13+
"build": "npm run lint && npm run clean:dist && npm run transpile && npm run copy:assets",
14+
"transpile": "./node_modules/.bin/tsc",
15+
"clean:dist": "./node_modules/.bin/gulp clean:dist",
16+
"copy:assets": "./node_modules/.bin/gulp copy:assets",
1517
"db:migrate": "./node_modules/.bin/knex migrate:latest",
1618
"db:migrate:rollback": "./node_modules/.bin/knex migrate:rollback",
1719
"db:seed": "./node_modules/.bin/knex seed:run",
1820
"db:reset": "npm run console db:reset",
1921
"console": "./node_modules/.bin/ts-node ./src/console/commander.ts",
2022
"serve": "./node_modules/.bin/nodemon --watch 'src/**/*.ts' --watch 'src/**/*.json'",
21-
"start": "node src/index.js"
23+
"start": "node dist/index.js"
2224
},
2325
"repository": "git+ssh://git@github.com/w3tec/express-typescript-boilerplate.git",
2426
"engines": {
@@ -78,14 +80,11 @@
7880
"debug": "^2.6.8",
7981
"dotenv": "^4.0.0",
8082
"express": "^4.15.3",
83+
"express-status-monitor": "^0.1.9",
8184
"faker": "^4.1.0",
8285
"gulp": "^3.9.1",
8386
"gulp-clean": "^0.3.2",
8487
"gulp-load-plugins": "^1.4.0",
85-
"gulp-plumber": "^1.1.0",
86-
"gulp-sourcemaps": "^2.6.0",
87-
"gulp-tslint": "^8.0.0",
88-
"gulp-typescript": "^3.1.4",
8988
"helmet": "^3.6.1",
9089
"inversify": "^4.1.0",
9190
"inversify-express-utils": "^3.5.1",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as express from 'express';
2+
import * as monitor from 'express-status-monitor';
3+
const swaggerUi = require('swagger-ui-express');
4+
import { Controller, Get, Response, Request } from 'inversify-express-utils';
5+
import { injectable } from 'inversify';
6+
import { Environment } from '../../core/Environment';
7+
8+
/**
9+
* HomeController is a public controller to give some
10+
* information about this api
11+
*/
12+
@injectable()
13+
@Controller('')
14+
export class ApiController {
15+
16+
@Get('/info')
17+
public getInfo( @Response() res: express.Response): any {
18+
const pkg = require('../../../package.json');
19+
return res.json({
20+
name: pkg.name,
21+
version: pkg.version,
22+
description: pkg.description
23+
});
24+
}
25+
26+
@Get('/status')
27+
public getStatus( @Request() req: express.Request, @Response() res: express.Response): any {
28+
return monitor().pageRoute(req, res);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)