Skip to content

Commit eba3bbf

Browse files
author
hirsch88
committed
Merge branch 'release/2.0.1'
2 parents 9f2963b + fb8bc48 commit eba3bbf

19 files changed

+64
-126
lines changed

.env.example

+1-1
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:3000"
6+
APP_HOST="http://localhost"
77
APP_URL_PREFIX="/api"
88
APP_PORT=3000
99

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: node_js
22
node_js:
3-
- "7.7.3"
3+
- "8.2.1"
44
install:
55
- yarn install
66
scripts:
7-
- nps test
8-
- nps build
7+
- npm test
8+
- npm start build
99
notifications:
1010
email: false

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ Create a new database with the name you have in your `.env`-file.
6868

6969
Then setup your application environment.
7070
```
71-
nps setup
71+
npm start setup
7272
```
7373

7474
> This installs all dependencies with yarn. After that it migrates the database and seeds some test data into it. So after that your development environment is ready to use.
7575
7676
### Step 3: Serve your App
7777
Go to the project dir and start your app with this npm script.
7878
```
79-
nps serve
79+
npm start serve
8080
```
8181

8282
> This starts a local server using `nodemon`, which will watch for any file changes and will restart the sever according to these changes.
@@ -149,26 +149,26 @@ All script are defined in the package.json file, but the most important ones are
149149
* Install all dependencies with `yarn install`
150150

151151
### Linting
152-
* Run code quality analysis using `nps lint`. This runs tslint.
152+
* Run code quality analysis using `npm start lint`. This runs tslint.
153153
* There is also a vscode task for this called `lint`.
154154

155155
### Tests
156-
* Run the unit tests using `nps test` (There is also a vscode task for this called `test`).
157-
* 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).
156+
* Run the unit tests using `npm start test` (There is also a vscode task for this called `test`).
157+
* Run the e2e tests using `npm start test:e2e` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
158158

159159
### Running in dev mode
160-
* Run `nps serve` to start nodemon with ts-node, to serve the app.
160+
* Run `npm start serve` to start nodemon with ts-node, to serve the app.
161161
* The server address will be displayed to you as `http://0.0.0.0:3000`
162162

163163
### Building the project and run it
164-
* Run `nps build` to generated all JavaScript files from the TypeScript sources (There is also a vscode task for this called `build`).
164+
* Run `npm start build` to generated all JavaScript files from the TypeScript sources (There is also a vscode task for this called `build`).
165165
* To start the builded app located in `dist` use `npm start`.
166166

167167
### Database
168-
* Run `nps db:migrate` to migrate schema changes to the database
169-
* Run `nps db:migrate:rollback` to rollback one migration
170-
* Run `nps db:seed` to seed sample data into the database
171-
* Run `nps db:reset` to rollback all migrations and migrate any migration again
168+
* Run `npm start db:migrate` to migrate schema changes to the database
169+
* Run `npm start db:migrate:rollback` to rollback one migration
170+
* Run `npm start db:seed` to seed sample data into the database
171+
* Run `npm start db:reset` to rollback all migrations and migrate any migration again
172172

173173
### Console
174174
* To run your own created command enter `npm run console <command-name>`.

appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
environment:
2-
nodejs_version: "7"
2+
nodejs_version: "8"
33

44
install:
55
- ps: Install-Product node $env:nodejs_version
66
- yarn install
77

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

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

package-scripts.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const { series, crossEnv, concurrent, rimraf, runInNewWindow } = require('nps-ut
22

33
module.exports = {
44
scripts: {
5+
default: {
6+
script: 'nps start'
7+
},
58
/**
69
* Starts the builded app from the dist directory
710
*/
@@ -53,10 +56,10 @@ module.exports = {
5356
)
5457
},
5558
pretest: {
56-
script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/unit/**/*.ts"'
59+
script: '\"./node_modules/.bin/tslint\" -c ./tslint.json -t stylish "./test/unit/**/*.ts"'
5760
},
5861
run: {
59-
script: './node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit'
62+
script: '\"./node_modules/.bin/cross-env\" NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit'
6063
},
6164
verbose: {
6265
script: 'nps "test --verbose"'
@@ -75,28 +78,28 @@ module.exports = {
7578
)
7679
},
7780
pretest: {
78-
script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/e2e/**/*.ts"'
81+
script: '\"./node_modules/.bin/tslint\" -c ./tslint.json -t stylish "./test/e2e/**/*.ts"'
7982
},
8083
verbose: {
8184
script: 'nps "test.e2e --verbose"'
8285
},
8386
run: series(
8487
`wait-on --timeout 120000 http-get://localhost:3000/api/info`,
85-
'./node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=e2e -i'
88+
'\"./node_modules/.bin/cross-env\" NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=e2e -i'
8689
),
8790
}
8891
},
8992
/**
9093
* Runs TSLint over your project
9194
*/
9295
lint: {
93-
script: `./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish`
96+
script: `"./node_modules/.bin/tslint" -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish`
9497
},
9598
/**
9699
* Transpile your app into javascript
97100
*/
98101
transpile: {
99-
script: `./node_modules/.bin/tsc`
102+
script: `"./node_modules/.bin/tsc"`
100103
},
101104
/**
102105
* Clean files and folders
@@ -106,7 +109,7 @@ module.exports = {
106109
script: series(`nps banner.clean`, `nps clean.dist`)
107110
},
108111
dist: {
109-
script: `./node_modules/.bin/trash './dist'`
112+
script: `"./node_modules/.bin/trash" './dist'`
110113
}
111114
},
112115
/**
@@ -178,11 +181,11 @@ function banner(name) {
178181
}
179182

180183
function copy(source, target) {
181-
return `./node_modules/.bin/copyup ${source} ${target}`
184+
return `"./node_modules/.bin/copyup" ${source} ${target}`
182185
}
183186

184187
function run(path) {
185-
return `./node_modules/.bin/ts-node ${path}`
188+
return `"./node_modules/.bin/ts-node" ${path}`
186189
}
187190

188191
function runFast(path) {

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "express-typescript-boilerplate",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
66
"engines": {
7-
"node": "8.2.1"
7+
"node": ">= 6.9.1"
88
},
99
"scripts": {
10-
"start": "node dist/app.js",
11-
"test": "nps test",
10+
"start": "nps",
11+
"test": "npm start test",
12+
"build": "npm start build",
1213
"ts-node": "./node_modules/.bin/ts-node",
1314
"ts-node:fast": "./node_modules/.bin/ts-node -F",
1415
"console": "npm run ts-node:fast -- ./src/console/lib/console.ts",
@@ -85,7 +86,7 @@
8586
"helmet": "^3.9.0",
8687
"inquirer": "^3.3.0",
8788
"inversify": "^4.5.0",
88-
"inversify-express-utils": "^4.1.0",
89+
"inversify-express-utils": "^4.2.2",
8990
"jsonwebtoken": "^8.1.0",
9091
"knex": "^0.13.0",
9192
"lodash": "^4.17.4",

src/api/middlewares/AuthenticateMiddleware.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { inject, named } from 'inversify';
1+
import {inject, named} from 'inversify';
22
import * as Request from 'request';
3-
import { Logger as LoggerType } from '../../core/Logger';
4-
import { Types, Core } from '../../constants';
5-
import { events } from '../../core/api/events';
6-
import { UserAuthenticatedListener } from '../listeners/user/UserAuthenticatedListener';
3+
import {Logger as LoggerType} from '../../core/Logger';
4+
import {Types, Core} from '../../constants';
5+
import {events} from '../../core/api/events';
6+
import {UserAuthenticatedListener} from '../listeners/user/UserAuthenticatedListener';
77

88

99
export class AuthenticateMiddleware implements interfaces.Middleware {
1010

1111
public log: LoggerType;
1212

13-
constructor(
14-
@inject(Types.Core) @named(Core.Logger) Logger: typeof LoggerType,
15-
@inject(Types.Lib) @named('request') private request: typeof Request
16-
) {
13+
constructor(@inject(Types.Core) @named(Core.Logger) Logger: typeof LoggerType,
14+
@inject(Types.Lib) @named('request') private request: typeof Request) {
1715
this.log = new Logger(__filename);
1816
}
1917

@@ -57,7 +55,7 @@ export class AuthenticateMiddleware implements interfaces.Middleware {
5755
}
5856

5957
private getToken(req: myExpress.Request): string | null {
60-
const authorization = req.headers.authorization;
58+
const authorization: string = req.headers.authorization as string;
6159

6260
// Retrieve the token form the Authorization header
6361
if (authorization && authorization.split(' ')[0] === 'Bearer') {

src/config/Database.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const DatabaseConfig = {
1616
client: process.env.DB_CLIENT,
1717
connection: process.env.DB_CONNECTION,
1818
pool: {
19-
min: parseInt(process.env.DB_POOL_MIN, 10),
20-
max: parseInt(process.env.DB_POOL_MAX, 10)
19+
min: parseInt(process.env.DB_POOL_MIN as string, 10),
20+
max: parseInt(process.env.DB_POOL_MAX as string, 10)
2121
},
2222
migrations: {
2323
directory: process.env.DB_MIGRATION_DIR,

src/config/LoggerConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import { Configurable } from '../core/App';
1313
export class LoggerConfig implements Configurable {
1414
public configure(): void {
1515
Logger.addAdapter('winston', WinstonAdapter);
16-
Logger.setAdapter(process.env.LOG_ADAPTER);
16+
Logger.setAdapter(process.env.LOG_ADAPTER as string);
1717
}
1818
}

src/console/templates/seed.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'reflect-metadata';
12
import * as Knex from 'knex';
23

34
import { Factory } from '../factories';

src/core/ApiInfo.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { ApiMonitor } from './ApiMonitor';
77
export class ApiInfo {
88

99
public static getRoute(): string {
10-
return process.env.APP_URL_PREFIX + process.env.API_INFO_ROUTE;
10+
return process.env.APP_URL_PREFIX as string + process.env.API_INFO_ROUTE;
1111
}
1212

1313
public setup(application: express.Application): void {
14-
if (Environment.isTruthy(process.env.API_INFO_ENABLED)) {
14+
if (Environment.isTruthy(process.env.API_INFO_ENABLED as string)) {
1515
application.get(
1616
ApiInfo.getRoute(),
1717
// @ts-ignore: False type definitions from express
@@ -20,11 +20,11 @@ export class ApiInfo {
2020
const links = {
2121
links: {}
2222
};
23-
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
23+
if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) {
2424
links.links['swagger'] =
2525
`${application.get('host')}${SwaggerUI.getRoute()}`;
2626
}
27-
if (Environment.isTruthy(process.env.MONITOR_ENABLED)) {
27+
if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) {
2828
links.links['monitor'] =
2929
`${application.get('host')}${ApiMonitor.getRoute()}`;
3030
}

src/core/ApiMonitor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { BasicAuthentication } from './BasicAuthentication';
77
export class ApiMonitor {
88

99
public static getRoute(): string {
10-
return process.env.MONITOR_ROUTE;
10+
return process.env.MONITOR_ROUTE as string;
1111
}
1212

1313
public setup(app: express.Application): void {
14-
if (Environment.isTruthy(process.env.MONITOR_ENABLED)) {
14+
if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) {
1515
app.use(monitor());
1616
app.get(ApiMonitor.getRoute(), BasicAuthentication(), monitor().pageRoute);
1717
}

src/core/BasicAuthentication.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as basicAuth from 'express-basic-auth';
44
export const BasicAuthentication = (): any => {
55
return basicAuth({
66
users: {
7-
[process.env.APP_BASIC_USER]: process.env.APP_BASIC_PASSWORD
7+
[process.env.APP_BASIC_USER as string]: process.env.APP_BASIC_PASSWORD as string
88
},
99
challenge: true
1010
});

src/core/Bootstrap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Bootstrap {
4040

4141
public setupInversifyExpressServer(app: express.Application, ioc: IoC): InversifyExpressServer {
4242
const inversifyExpressServer = new InversifyExpressServer(ioc.container, undefined, {
43-
rootPath: process.env.APP_URL_PREFIX
43+
rootPath: process.env.APP_URL_PREFIX as string
4444
}, app);
4545
// @ts-ignore: False type definitions from express
4646
inversifyExpressServer.setConfig((a) => a.use(extendExpressResponse));

src/core/Server.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ export class Server {
7272
this.log.debug(`Environment : ${Environment.getNodeEnv()}`);
7373
this.log.debug(`Version : ${Environment.getPkg().version}`);
7474
this.log.debug(``);
75-
if (Environment.isTruthy(process.env.API_INFO_ENABLED)) {
75+
if (Environment.isTruthy(process.env.API_INFO_ENABLED as string)) {
7676
this.log.debug(`API Info : ${app.get('host')}${ApiInfo.getRoute()}`);
7777
}
78-
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
78+
if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) {
7979
this.log.debug(`Swagger : ${app.get('host')}${SwaggerUI.getRoute()}`);
8080
}
81-
if (Environment.isTruthy(process.env.MONITOR_ENABLED)) {
81+
if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) {
8282
this.log.debug(`Monitor : ${app.get('host')}${ApiMonitor.getRoute()}`);
8383
}
8484
this.log.debug('-------------------------------------------------------');

src/core/SwaggerUI.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { BasicAuthentication } from './BasicAuthentication';
88
export class SwaggerUI {
99

1010
public static getRoute(): string {
11-
return process.env.SWAGGER_ROUTE;
11+
return process.env.SWAGGER_ROUTE as string;
1212
}
1313

1414
public setup(app: express.Application): void {
15-
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
15+
if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) {
1616
const baseFolder = __dirname.indexOf(`${path.sep}src${path.sep}`) >= 0 ? `${path.sep}src${path.sep}` : `${path.sep}dist${path.sep}`;
1717
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
18-
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE));
18+
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE as string));
1919
const packageJson = require(path.join(basePath, 'package.json'));
2020

2121
// Add npm infos to the swagger doc

src/database/seeds/create_users.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import 'reflect-metadata';
12
import * as Knex from 'knex';
23

34
import { Factory } from '../factories';
45
import { User } from '../../api/models/User';
56

6-
77
exports.seed = async (db: Knex) => {
88
const factory = Factory.getInstance();
99
await factory.get(User)

0 commit comments

Comments
 (0)