Skip to content

Develop #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "7.7.3"
- "8.2.1"
install:
- yarn install
scripts:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
nodejs_version: "7"
nodejs_version: "8"

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
18 changes: 9 additions & 9 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
Expand All @@ -75,28 +75,28 @@ 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'
),
}
},
/**
* 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
Expand All @@ -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'`
}
},
/**
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 8 additions & 10 deletions src/api/middlewares/AuthenticateMiddleware.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions src/config/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/config/LoggerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/console/templates/seed.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata';
import * as Knex from 'knex';

import { Factory } from '../factories';
Expand Down
8 changes: 4 additions & 4 deletions src/core/ApiInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()}`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ApiMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/BasicAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/Bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/core/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('-------------------------------------------------------');
Expand Down
6 changes: 3 additions & 3 deletions src/core/SwaggerUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/database/seeds/create_users.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down