Skip to content

Commit

Permalink
Merge branch 'release/3.0.0-rc.2'
Browse files Browse the repository at this point in the history
* release/3.0.0-rc.2: (23 commits)
  bump version
  Fix typescript version
  Fix swagger route
  Fix ts-node fastMode and fix setup task
  Add recommanded vscode extensions
  Format files
  Update lodash
  Move logger to lib
  Fix paths in env file
  Fix naming of docker file
  Move env helper functions to the utils file
  Move env.ts to the src folder
  Move banner.ts to the lib folder
  Adjust `table of content` heading
  Fix typescript errors
  Updates dependencies
  Update EntityFactory.ts
  Update EntityFactory.ts
  Seed entity with lazy relations
  extend docker section in readme
  ...
  • Loading branch information
hirsch88 committed Feb 27, 2018
2 parents 5a78466 + cd5145e commit db1129f
Show file tree
Hide file tree
Showing 95 changed files with 1,232 additions and 539 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
node_modules
test
.editorconfig
.env.example
.gitignore
.travis.yml
appveyor.yml
icon.png
LICENSE
README.md
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# APPLICATION
#
APP_NAME="express-typescript-boilerplate"
APP_ROUTE="http://localhost:3000"
APP_SCHEMA="http"
APP_HOST="localhost"
APP_PORT="3000"
APP_ROUTE_PREFIX="/api"
APP_BANNER=true

Expand Down
4 changes: 3 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# APPLICATION
#
APP_NAME="express-typescript-boilerplate"
APP_ROUTE="http://localhost:3000"
APP_SCHEMA="http"
APP_HOST="localhost"
APP_PORT="3000"
APP_ROUTE_PREFIX="/api"
APP_BANNER=false

Expand Down
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"eg2.tslint",
"steoates.autoimport",
"EditorConfig.EditorConfig",
"christian-kohler.path-intellisense",
"mike-co.import-sorter",
"mikestead.dotenv",
"Orta.vscode-jest"
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"files.exclude": {
"tsconfig.build.json": true,
"ormconfig.json": true
}
},
"importSorter.generalConfiguration.sortOnBeforeSave": true,
"files.trimTrailingWhitespace": true,
"editor.formatOnSave": false
}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:alpine

# Create work directory
WORKDIR /usr/src/app

# Install runtime dependencies
RUN npm install yarn -g

# Copy app source to work directory
COPY . /usr/src/app

# Install app dependencies
RUN yarn install

# Build and run the app
CMD npm start serve
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Try it!! We are happy to hear your feedback or any kind of new features.
- **GraphQL** provides as a awesome query language for our api [GraphQL](http://graphql.org/).
- **DataLoaders** helps with performance thanks to caching and batching [DataLoaders](https://github.com/facebook/dataloader).

# Table of Contents
## Table of Contents

- [Getting Started](#getting-started)
- [Scripts and Tasks](#scripts-and-tasks)
Expand Down Expand Up @@ -371,6 +371,85 @@ The last step is the easiest, just hit the following command in your terminal, b
npm start db.seed
```
## Run in Docker container
### Install Docker
Before you start, make sure you have a recent version of [Docker](https://docs.docker.com/engine/installation/) installed
### Build Docker image
```shell
docker build -t <your-image-name> .
```
### Run Docker image in container and map port
The port which runs your application inside Docker container is either configured as `PORT` property in your `.env` configuration file or passed to Docker container via environment variable `PORT`. Default port is `3000`.
#### Run image in detached mode
```shell
docker run -d -p <port-on-host>:<port-inside-docker-container> <your-image-name>
```
#### Run image in foreground mode
```shell
docker run -i -t -p <port-on-host>:<port-inside-docker-container> <your-image-name>
```
### Stop Docker container
#### Detached mode
```shell
docker stop <container-id>
```
You can get a list of all running Docker container and its ids by following command
```shell
docker images
```
#### Foreground mode
Go to console and press <CTRL> + C at any time.
### Docker environment variables
There are several options to configure your app inside a Docker container
#### project .env file
You can use `.env` file in project root folder which will be copied inside Docker image. If you want to change a property inside `.env` you have to rebuild your Docker image.
#### run options
You can also change app configuration by passing environment variables via `docker run` option `-e` or `--env`.
```shell
docker run --env DB_HOST=localhost -e DB_PORT=3306
```
#### environment file
Last but not least you can pass a config file to `docker run`.
```shell
docker run --env-file ./env.list
```
`env.list` example:
```
# this is a comment
DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
```
## Further Documentations
| Name & Link | Description |
Expand Down
3 changes: 1 addition & 2 deletions commands/banner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as figlet from 'figlet';
import chalk from 'chalk';

import * as figlet from 'figlet';

figlet(process.argv[2], (error: any, data: any) => {
if (error) {
Expand Down
15 changes: 5 additions & 10 deletions commands/ormconfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as dotenv from 'dotenv';
dotenv.config();

import * as path from 'path';
import * as Chalk from 'chalk';
import * as jsonfile from 'jsonfile';
import { env } from '../src/core/env';
import * as path from 'path';

import { env } from '../src/env';

dotenv.config();

const content = {
type: env.db.type,
Expand All @@ -24,11 +23,7 @@ const content = {
const filePath = path.join(process.cwd(), 'ormconfig.json');
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
if (err === null) {
const chalk = Chalk.default;
console.log('👍 ',
chalk.gray.underline('generated:'),
chalk.blue.bold('ormconfig.json')
);
process.exit(0);
} else {
console.error('Failed to generate the ormconfig.json', err);
process.exit(1);
Expand Down
13 changes: 4 additions & 9 deletions commands/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as path from 'path';
import * as Chalk from 'chalk';
import * as jsonfile from 'jsonfile';
import * as tsconfig from '../tsconfig.json';
import * as path from 'path';

import * as tsconfig from '../tsconfig.json';

const content: any = tsconfig;
content.include = [
Expand All @@ -12,13 +11,9 @@ content.include = [
const filePath = path.join(process.cwd(), 'tsconfig.build.json');
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
if (err === null) {
const chalk = Chalk.default;
console.log('👍 ',
chalk.gray.underline('generated:'),
chalk.blue.bold('tsconfig.build.json')
);
process.exit(0);
} else {
console.error('Failed to generate the otsconfig.build.json', err);
console.error('Failed to generate the tsconfig.build.json', err);
process.exit(1);
}
});
20 changes: 10 additions & 10 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ module.exports = {
description: 'Serves the current app and watches for changes to restart it'
},
/**
* Setup's stuff
* Setup of the development environment
*/
setup: {
db: {
script: series(
'nps db.migrate',
'nps db.seed'
),
description: 'Setup`s the database by migrating and seeding'
}
script: series(
'yarn install',
'nps db.drop',
'nps db.migrate',
'nps db.seed'
),
description: 'Setup`s the development environment(yarn & database)'
},
/**
* Creates the needed configuration files
Expand Down Expand Up @@ -267,11 +267,11 @@ function copy(source, target) {
}

function run(path) {
return `ts-node ${path}`;
return `ts-node --typeCheck ${path}`;
}

function runFast(path) {
return run(`-F ${path}`);
return `ts-node ${path}`;
}

function tslint(path) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-typescript-boilerplate",
"version": "3.0.0-rc.1",
"version": "3.0.0-rc.2",
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
"main": "src/app.ts",
"scripts": {
Expand Down Expand Up @@ -94,7 +94,7 @@
"typedi": "^0.5.2",
"typeorm": "^0.1.3",
"typeorm-typedi-extensions": "^0.1.1",
"typescript": "^2.6.1",
"typescript": "2.6.2",
"uuid": "^3.1.0",
"winston": "^2.4.0"
},
Expand Down
10 changes: 6 additions & 4 deletions src/api/controllers/PetController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { JsonController, Get, Post, Put, Param, Delete, Body, OnUndefined, Authorized } from 'routing-controllers';
import { PetService } from '../services/PetService';
import { Pet } from '../models/Pet';
import { PetNotFoundError } from '../errors/PetNotFoundError';
import {
Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put
} from 'routing-controllers';

import { PetNotFoundError } from '../errors/PetNotFoundError';
import { Pet } from '../models/Pet';
import { PetService } from '../services/PetService';

@Authorized()
@JsonController('/pets')
Expand Down
10 changes: 6 additions & 4 deletions src/api/controllers/UserController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { JsonController, Get, Post, Put, Param, Delete, Body, OnUndefined, Authorized, CurrentUser } from 'routing-controllers';
import { UserService } from '../services/UserService';
import { User } from '../models/User';
import { UserNotFoundError } from '../errors/UserNotFoundError';
import {
Authorized, Body, CurrentUser, Delete, Get, JsonController, OnUndefined, Param, Post, Put
} from 'routing-controllers';

import { UserNotFoundError } from '../errors/UserNotFoundError';
import { User } from '../models/User';
import { UserService } from '../services/UserService';

@Authorized()
@JsonController('/users')
Expand Down
4 changes: 1 addition & 3 deletions src/api/middlewares/CompressionMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import * as express from 'express';
import * as compression from 'compression';
import * as express from 'express';
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';


@Middleware({ type: 'before' })
export class CompressionMiddleware implements ExpressMiddlewareInterface {

Expand Down
6 changes: 3 additions & 3 deletions src/api/middlewares/ErrorHandlerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as express from 'express';
import { Middleware, ExpressErrorMiddlewareInterface, HttpError } from 'routing-controllers';
import { env } from '../../core/env';
import { Logger, LoggerInterface } from '../../decorators/Logger';
import { ExpressErrorMiddlewareInterface, HttpError, Middleware } from 'routing-controllers';

import { Logger, LoggerInterface } from '../../decorators/Logger';
import { env } from '../../env';

@Middleware({ type: 'after' })
export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
Expand Down
5 changes: 2 additions & 3 deletions src/api/middlewares/LogMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import * as express from 'express';
import * as morgan from 'morgan';
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';
import { Logger } from '../../core/Logger';
import { env } from '../../core/env';

import { env } from '../../env';
import { Logger } from '../../lib/logger';

@Middleware({ type: 'before' })
export class LogMiddleware implements ExpressMiddlewareInterface {
Expand Down
2 changes: 0 additions & 2 deletions src/api/middlewares/SecurityHstsMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import * as express from 'express';
import * as helmet from 'helmet';
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';


@Middleware({ type: 'before' })
export class SecurityHstsMiddleware implements ExpressMiddlewareInterface {

Expand Down
2 changes: 0 additions & 2 deletions src/api/middlewares/SecurityMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import * as express from 'express';
import * as helmet from 'helmet';
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';


@Middleware({ type: 'before' })
export class SecurityMiddleware implements ExpressMiddlewareInterface {

Expand Down
2 changes: 0 additions & 2 deletions src/api/middlewares/SecurityNoCacheMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import * as express from 'express';
import * as helmet from 'helmet';
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers';


@Middleware({ type: 'before' })
export class SecurityNoCacheMiddleware implements ExpressMiddlewareInterface {

Expand Down
4 changes: 2 additions & 2 deletions src/api/models/Pet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { IsNotEmpty } from 'class-validator';
import { User } from './User';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';

import { User } from './User';

@Entity()
export class Pet {
Expand Down

0 comments on commit db1129f

Please sign in to comment.