diff --git a/.env.example b/.env.example index 91427e1f..f20db7e1 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ # APP_NAME="express-typescript-boilerplate" APP_ENV="local" -APP_HOST="http://localhost:3000" +APP_HOST="http://localhost" APP_URL_PREFIX="/api" APP_PORT=3000 diff --git a/.travis.yml b/.travis.yml index 54dac591..ebc35194 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "7.7.3" + - "8.2.1" install: - yarn install scripts: diff --git a/appveyor.yml b/appveyor.yml index 6f1e255d..ae3301ff 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ environment: - nodejs_version: "7" + nodejs_version: "8" install: - ps: Install-Product node $env:nodejs_version diff --git a/package-scripts.js b/package-scripts.js index cf7f22e4..87a7c0dc 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -53,10 +53,10 @@ module.exports = { ) }, pretest: { - script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/unit/**/*.ts"' + script: '\"./node_modules/.bin/tslint\" -c ./tslint.json -t stylish "./test/unit/**/*.ts"' }, run: { - script: './node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit' + script: '\"./node_modules/.bin/cross-env\" NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit' }, verbose: { script: 'nps "test --verbose"' @@ -75,14 +75,14 @@ module.exports = { ) }, pretest: { - script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/e2e/**/*.ts"' + script: '\"./node_modules/.bin/tslint\" -c ./tslint.json -t stylish "./test/e2e/**/*.ts"' }, verbose: { script: 'nps "test.e2e --verbose"' }, run: series( `wait-on --timeout 120000 http-get://localhost:3000/api/info`, - './node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=e2e -i' + '\"./node_modules/.bin/cross-env\" NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=e2e -i' ), } }, @@ -90,13 +90,13 @@ module.exports = { * Runs TSLint over your project */ lint: { - script: `./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish` + script: `"./node_modules/.bin/tslint" -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish` }, /** * Transpile your app into javascript */ transpile: { - script: `./node_modules/.bin/tsc` + script: `"./node_modules/.bin/tsc"` }, /** * Clean files and folders @@ -106,7 +106,7 @@ module.exports = { script: series(`nps banner.clean`, `nps clean.dist`) }, dist: { - script: `./node_modules/.bin/trash './dist'` + script: `"./node_modules/.bin/trash" './dist'` } }, /** @@ -178,11 +178,11 @@ function banner(name) { } function copy(source, target) { - return `./node_modules/.bin/copyup ${source} ${target}` + return `"./node_modules/.bin/copyup" ${source} ${target}` } function run(path) { - return `./node_modules/.bin/ts-node ${path}` + return `"./node_modules/.bin/ts-node" ${path}` } function runFast(path) { diff --git a/package.json b/package.json index b2b64b55..d8cd9ab7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A delightful way to building a RESTful API with NodeJs & TypeScript", "main": "src/app.ts", "engines": { - "node": "8.2.1" + "node": ">= 6.9.1" }, "scripts": { "start": "node dist/app.js", @@ -85,7 +85,7 @@ "helmet": "^3.9.0", "inquirer": "^3.3.0", "inversify": "^4.5.0", - "inversify-express-utils": "^4.1.0", + "inversify-express-utils": "^4.2.2", "jsonwebtoken": "^8.1.0", "knex": "^0.13.0", "lodash": "^4.17.4", diff --git a/src/api/middlewares/AuthenticateMiddleware.ts b/src/api/middlewares/AuthenticateMiddleware.ts index 4621d4b6..ef49430f 100644 --- a/src/api/middlewares/AuthenticateMiddleware.ts +++ b/src/api/middlewares/AuthenticateMiddleware.ts @@ -1,19 +1,17 @@ -import { inject, named } from 'inversify'; +import {inject, named} from 'inversify'; import * as Request from 'request'; -import { Logger as LoggerType } from '../../core/Logger'; -import { Types, Core } from '../../constants'; -import { events } from '../../core/api/events'; -import { UserAuthenticatedListener } from '../listeners/user/UserAuthenticatedListener'; +import {Logger as LoggerType} from '../../core/Logger'; +import {Types, Core} from '../../constants'; +import {events} from '../../core/api/events'; +import {UserAuthenticatedListener} from '../listeners/user/UserAuthenticatedListener'; export class AuthenticateMiddleware implements interfaces.Middleware { public log: LoggerType; - constructor( - @inject(Types.Core) @named(Core.Logger) Logger: typeof LoggerType, - @inject(Types.Lib) @named('request') private request: typeof Request - ) { + constructor(@inject(Types.Core) @named(Core.Logger) Logger: typeof LoggerType, + @inject(Types.Lib) @named('request') private request: typeof Request) { this.log = new Logger(__filename); } @@ -57,7 +55,7 @@ export class AuthenticateMiddleware implements interfaces.Middleware { } private getToken(req: myExpress.Request): string | null { - const authorization = req.headers.authorization; + const authorization: string = req.headers.authorization as string; // Retrieve the token form the Authorization header if (authorization && authorization.split(' ')[0] === 'Bearer') { diff --git a/src/config/Database.ts b/src/config/Database.ts index eb7d95a1..b4aaf1e4 100755 --- a/src/config/Database.ts +++ b/src/config/Database.ts @@ -16,8 +16,8 @@ export const DatabaseConfig = { client: process.env.DB_CLIENT, connection: process.env.DB_CONNECTION, pool: { - min: parseInt(process.env.DB_POOL_MIN, 10), - max: parseInt(process.env.DB_POOL_MAX, 10) + min: parseInt(process.env.DB_POOL_MIN as string, 10), + max: parseInt(process.env.DB_POOL_MAX as string, 10) }, migrations: { directory: process.env.DB_MIGRATION_DIR, diff --git a/src/config/LoggerConfig.ts b/src/config/LoggerConfig.ts index 320674fe..2f34bc73 100644 --- a/src/config/LoggerConfig.ts +++ b/src/config/LoggerConfig.ts @@ -13,6 +13,6 @@ import { Configurable } from '../core/App'; export class LoggerConfig implements Configurable { public configure(): void { Logger.addAdapter('winston', WinstonAdapter); - Logger.setAdapter(process.env.LOG_ADAPTER); + Logger.setAdapter(process.env.LOG_ADAPTER as string); } } diff --git a/src/console/templates/seed.hbs b/src/console/templates/seed.hbs index 6282d301..f5903c41 100644 --- a/src/console/templates/seed.hbs +++ b/src/console/templates/seed.hbs @@ -1,3 +1,4 @@ +import 'reflect-metadata'; import * as Knex from 'knex'; import { Factory } from '../factories'; diff --git a/src/core/ApiInfo.ts b/src/core/ApiInfo.ts index 23edecac..358728b8 100644 --- a/src/core/ApiInfo.ts +++ b/src/core/ApiInfo.ts @@ -7,11 +7,11 @@ import { ApiMonitor } from './ApiMonitor'; export class ApiInfo { public static getRoute(): string { - return process.env.APP_URL_PREFIX + process.env.API_INFO_ROUTE; + return process.env.APP_URL_PREFIX as string + process.env.API_INFO_ROUTE; } public setup(application: express.Application): void { - if (Environment.isTruthy(process.env.API_INFO_ENABLED)) { + if (Environment.isTruthy(process.env.API_INFO_ENABLED as string)) { application.get( ApiInfo.getRoute(), // @ts-ignore: False type definitions from express @@ -20,11 +20,11 @@ export class ApiInfo { const links = { links: {} }; - if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) { + if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) { links.links['swagger'] = `${application.get('host')}${SwaggerUI.getRoute()}`; } - if (Environment.isTruthy(process.env.MONITOR_ENABLED)) { + if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) { links.links['monitor'] = `${application.get('host')}${ApiMonitor.getRoute()}`; } diff --git a/src/core/ApiMonitor.ts b/src/core/ApiMonitor.ts index c9dd020e..9ee0d491 100644 --- a/src/core/ApiMonitor.ts +++ b/src/core/ApiMonitor.ts @@ -7,11 +7,11 @@ import { BasicAuthentication } from './BasicAuthentication'; export class ApiMonitor { public static getRoute(): string { - return process.env.MONITOR_ROUTE; + return process.env.MONITOR_ROUTE as string; } public setup(app: express.Application): void { - if (Environment.isTruthy(process.env.MONITOR_ENABLED)) { + if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) { app.use(monitor()); app.get(ApiMonitor.getRoute(), BasicAuthentication(), monitor().pageRoute); } diff --git a/src/core/BasicAuthentication.ts b/src/core/BasicAuthentication.ts index 61584b89..5da6c2df 100644 --- a/src/core/BasicAuthentication.ts +++ b/src/core/BasicAuthentication.ts @@ -4,7 +4,7 @@ import * as basicAuth from 'express-basic-auth'; export const BasicAuthentication = (): any => { return basicAuth({ users: { - [process.env.APP_BASIC_USER]: process.env.APP_BASIC_PASSWORD + [process.env.APP_BASIC_USER as string]: process.env.APP_BASIC_PASSWORD as string }, challenge: true }); diff --git a/src/core/Bootstrap.ts b/src/core/Bootstrap.ts index 363d536c..c81ef74f 100644 --- a/src/core/Bootstrap.ts +++ b/src/core/Bootstrap.ts @@ -40,7 +40,7 @@ export class Bootstrap { public setupInversifyExpressServer(app: express.Application, ioc: IoC): InversifyExpressServer { const inversifyExpressServer = new InversifyExpressServer(ioc.container, undefined, { - rootPath: process.env.APP_URL_PREFIX + rootPath: process.env.APP_URL_PREFIX as string }, app); // @ts-ignore: False type definitions from express inversifyExpressServer.setConfig((a) => a.use(extendExpressResponse)); diff --git a/src/core/Server.ts b/src/core/Server.ts index 2506dadc..2f66176f 100644 --- a/src/core/Server.ts +++ b/src/core/Server.ts @@ -72,13 +72,13 @@ export class Server { this.log.debug(`Environment : ${Environment.getNodeEnv()}`); this.log.debug(`Version : ${Environment.getPkg().version}`); this.log.debug(``); - if (Environment.isTruthy(process.env.API_INFO_ENABLED)) { + if (Environment.isTruthy(process.env.API_INFO_ENABLED as string)) { this.log.debug(`API Info : ${app.get('host')}${ApiInfo.getRoute()}`); } - if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) { + if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) { this.log.debug(`Swagger : ${app.get('host')}${SwaggerUI.getRoute()}`); } - if (Environment.isTruthy(process.env.MONITOR_ENABLED)) { + if (Environment.isTruthy(process.env.MONITOR_ENABLED as string)) { this.log.debug(`Monitor : ${app.get('host')}${ApiMonitor.getRoute()}`); } this.log.debug('-------------------------------------------------------'); diff --git a/src/core/SwaggerUI.ts b/src/core/SwaggerUI.ts index eac1eef9..a6c26cbf 100644 --- a/src/core/SwaggerUI.ts +++ b/src/core/SwaggerUI.ts @@ -8,14 +8,14 @@ import { BasicAuthentication } from './BasicAuthentication'; export class SwaggerUI { public static getRoute(): string { - return process.env.SWAGGER_ROUTE; + return process.env.SWAGGER_ROUTE as string; } public setup(app: express.Application): void { - if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) { + if (Environment.isTruthy(process.env.SWAGGER_ENABLED as string)) { const baseFolder = __dirname.indexOf(`${path.sep}src${path.sep}`) >= 0 ? `${path.sep}src${path.sep}` : `${path.sep}dist${path.sep}`; const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder)); - const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE)); + const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE as string)); const packageJson = require(path.join(basePath, 'package.json')); // Add npm infos to the swagger doc diff --git a/src/database/seeds/create_users.ts b/src/database/seeds/create_users.ts index f775cc0c..f3eaf4d4 100644 --- a/src/database/seeds/create_users.ts +++ b/src/database/seeds/create_users.ts @@ -1,9 +1,9 @@ +import 'reflect-metadata'; import * as Knex from 'knex'; import { Factory } from '../factories'; import { User } from '../../api/models/User'; - exports.seed = async (db: Knex) => { const factory = Factory.getInstance(); await factory.get(User) diff --git a/yarn.lock b/yarn.lock index d962c7fa..61331778 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2309,7 +2309,7 @@ invariant@^2.2.2: dependencies: loose-envify "^1.0.0" -inversify-express-utils@^4.1.0: +inversify-express-utils@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/inversify-express-utils/-/inversify-express-utils-4.2.2.tgz#dd0a733cfdc7250a09132f7e694afd928ede6583" dependencies: