Skip to content

Commit 3da310e

Browse files
author
hirsch88
committed
Merge branch 'release/2.0.0-beta.6'
2 parents 87e29b1 + e4faa9e commit 3da310e

22 files changed

+566
-298
lines changed

.env.example

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
APP_NAME="express-typescript-boilerplate"
55
APP_ENV="local"
6-
APP_HOST="http://localhost"
6+
APP_HOST="http://localhost:3000"
77
APP_URL_PREFIX="/api"
88
APP_PORT=3000
99

@@ -13,6 +13,12 @@ APP_PORT=3000
1313
LOG_LEVEL="debug"
1414
LOG_ADAPTER="winston"
1515

16+
#
17+
# APPLICATION
18+
#
19+
APP_BASIC_USER="admin"
20+
APP_BASIC_PASSWORD="1234"
21+
1622
#
1723
# API Info
1824
#
@@ -23,14 +29,14 @@ API_INFO_ROUTE="/info"
2329
# Swagger Documentation
2430
#
2531
SWAGGER_ENABLED=true
26-
SWAGGER_ROUTE="/docs"
32+
SWAGGER_ROUTE="/swagger"
2733
SWAGGER_FILE="/src/api/swagger.json"
2834

2935
#
3036
# Monitor
3137
#
3238
MONITOR_ENABLED=true
33-
MONITOR_ROUTE="/status"
39+
MONITOR_ROUTE="/monitor"
3440

3541
#
3642
# DATABASE
@@ -53,5 +59,4 @@ DB_SEEDS_DIR="./src/database/seeds"
5359
#
5460
# Auth0
5561
#
56-
# AUTH0_HOST="https://w3tecch.auth0.com"
5762
AUTH0_HOST="http://localhost:3333"

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ node_js:
44
install:
55
- yarn install
66
scripts:
7-
- npm test
8-
- npm run build
7+
- nps test
8+
- nps build
99
notifications:
1010
email: false

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Try it!! We are happy to hear your feedback or any kind of new features.
3535
- **Easy Exception Handling** with our own simple and easy to adopt logic. You will love it.
3636
- **Easy Data Seeding** with our own factories.
3737
- **Custom Commands** are also available in our setup and really easy to use or even extend.
38+
- **Custom Validators** to validate your request even better and stricter. [custom-validation-classes](https://github.com/pleerock/class-validator#custom-validation-classes)
3839
- **Scaffolding Commands** will speed up your development tremendously as you should focus on business code and not scaffolding.
3940
- **Smart Validation** thanks to [class-validator](https://github.com/pleerock/class-validator) with some nice annotations.
4041
- **API Documentation** thanks to [swagger](http://swagger.io/).
@@ -152,7 +153,7 @@ All script are defined in the package.json file, but the most important ones are
152153
* There is also a vscode task for this called `lint`.
153154

154155
### Tests
155-
* Run the unit tests using `npm test` (There is also a vscode task for this called `test`).
156+
* Run the unit tests using `nps test` (There is also a vscode task for this called `test`).
156157
* Run the e2e tests using `nps test:e2e` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
157158

158159
### Running in dev mode
@@ -185,6 +186,7 @@ All the templates for the commands are located in `src/console/templates`.
185186
* `npm run console make:request <file>` - Generates a basic request.
186187
* `npm run console make:listener <file>` - Generates a basic listener.
187188
* `npm run console make:exception <file>` - Generates a basic exception.
189+
* `npm run console make:validator <file>` - Generates a custom validator.
188190
* `npm run console update:targets <file>` - Reads all the API files and generate a new `constants/Targets.ts` file out of it.
189191

190192
**Example**
@@ -230,6 +232,7 @@ The route prefix is `/api` by default, but you can change this in the .env file.
230232
| **src/api/repositories/** | Repository / DB layer |
231233
| **src/api/requests/** | Request bodys with validations |
232234
| **src/api/services/** | Service layer |
235+
| **src/api/validators/** | Custom validators, which can be used in the request classes |
233236
| **src/api/** swagger.json | Swagger documentation |
234237
| **src/console/** | Command line scripts |
235238
| **src/config/** | Configurations like database or logger |

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ install:
66
- yarn install
77

88
build_script:
9-
- npm run build
9+
- nps build
1010

1111
test_script:
12-
- npm test
12+
- nps test

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "express-typescript-boilerplate",
3-
"version": "2.0.0-beta.5",
3+
"version": "2.0.0-beta.6",
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
6+
"engines": {
7+
"node": "8.2.1"
8+
},
69
"scripts": {
710
"start": "node dist/app.js",
811
"test": "nps test",
@@ -60,6 +63,7 @@
6063
"@types/request": "^2.0.7",
6164
"@types/request-promise": "^4.1.39",
6265
"@types/serve-favicon": "^2.2.29",
66+
"@types/uuid": "^3.4.3",
6367
"@types/winston": "^2.3.7",
6468
"body-parser": "^1.18.2",
6569
"bookshelf": "^0.10.4",
@@ -72,6 +76,7 @@
7276
"cors": "^2.8.4",
7377
"dotenv": "^4.0.0",
7478
"express": "^4.16.2",
79+
"express-basic-auth": "^1.1.3",
7580
"express-status-monitor": "^1.0.1",
7681
"faker": "^4.1.0",
7782
"figlet": "^1.2.0",
@@ -99,6 +104,7 @@
99104
"ts-node": "^3.3.0",
100105
"tslint": "^5.8.0",
101106
"typescript": "^2.6.1",
107+
"uuid": "^3.1.0",
102108
"wait-on": "^2.0.2",
103109
"winston": "^2.4.0"
104110
},

src/api/requests/user/UserCreateRequest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { IsEmail, IsNotEmpty } from 'class-validator';
1+
import { IsEmail, IsNotEmpty, Validate } from 'class-validator';
22
import { RequestBody } from '../../../core/api/RequestBody';
3+
import { EndsWithValidator } from '../../Validators/EndsWithValidator';
34

45
/**
56
* This class is used for create request. Create a new instance
@@ -20,6 +21,7 @@ export class UserCreateRequest extends RequestBody {
2021

2122
@IsNotEmpty()
2223
@IsEmail()
24+
@Validate(EndsWithValidator, ['@gmail.com', '@w3tec.ch'])
2325
public email: string;
2426

2527
public picture: string;

src/api/requests/user/UserUpdateRequest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { IsEmail, IsNotEmpty } from 'class-validator';
1+
import { IsEmail, IsNotEmpty, Validate } from 'class-validator';
22
import { RequestBody } from '../../../core/api/RequestBody';
3+
import { EndsWithValidator } from '../../Validators/EndsWithValidator';
34

45
/**
56
* This class is used for update request. Create a new instance
@@ -19,6 +20,7 @@ export class UserUpdateRequest extends RequestBody {
1920
public lastName: string;
2021

2122
@IsEmail()
23+
@Validate(EndsWithValidator, ['@gmail.com', '@w3tec.ch'])
2224
public email: string;
2325

2426
@IsNotEmpty()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as _ from 'lodash';
2+
import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
3+
4+
5+
@ValidatorConstraint({ name: 'endsWith', async: false })
6+
export class EndsWithValidator implements ValidatorConstraintInterface {
7+
8+
public validate(text: string, args: ValidationArguments): boolean {
9+
for (const ending of args.constraints) {
10+
if (_.endsWith(text, ending)) {
11+
return true;
12+
}
13+
}
14+
return false;
15+
}
16+
17+
public defaultMessage(args: ValidationArguments): string {
18+
return 'Incorrect suffix';
19+
}
20+
21+
}

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
import 'reflect-metadata';
1414
import { App } from './core/App';
15-
import { CustomConfig } from './config/CustomConfig';
15+
import { CustomHeaderConfig } from './config/CustomHeaderConfig';
1616

1717
export const app = new App();
1818

1919

2020
// Here you can add more custom configurations
21-
app.configure(new CustomConfig());
21+
app.configure(new CustomHeaderConfig());
2222

2323
// Launch the server with all his awesome features.
2424
app.bootstrap();

src/config/CustomConfig.ts

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

0 commit comments

Comments
 (0)