├── .gitignore ├── .prettierrc ├── README.md ├── nest-cli.json ├── nodemon-debug.json ├── nodemon.json ├── package.json ├── src ├── app.controller.spec.ts ├── app.controller.ts ├── app.module.ts ├── app.service.ts ├── auth │ ├── auth.module.ts │ ├── auth.service.spec.ts │ ├── auth.service.ts │ ├── auth │ │ ├── auth.controller.spec.ts │ │ └── auth.controller.ts │ ├── user.entity.ts │ ├── user.service.spec.ts │ └── user.service.ts ├── contacts │ ├── contact.entity.ts │ ├── contacts.module.ts │ ├── contacts.service.spec.ts │ ├── contacts.service.ts │ └── contacts │ │ ├── contacts.controller.spec.ts │ │ └── contacts.controller.ts ├── main.hmr.ts └── main.ts ├── test ├── app.e2e-spec.ts └── jest-e2e.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | db 3 | package-lock.json 4 | # See http://help.github.com/ignore-files/ for more about ignoring files. 5 | 6 | # compiled output 7 | /dist 8 | /tmp 9 | /out-tsc 10 | 11 | /avatars 12 | 13 | # dependencies 14 | /node_modules 15 | 16 | # IDEs and editors 17 | /.idea 18 | .project 19 | .classpath 20 | .c9/ 21 | *.launch 22 | .settings/ 23 | *.sublime-workspace 24 | 25 | # IDE - VSCode 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | 32 | # misc 33 | /.sass-cache 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | npm-debug.log 38 | yarn-error.log 39 | testem.log 40 | /typings 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master 6 | [travis-url]: https://travis-ci.org/nestjs/nest 7 | [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux 8 | [linux-url]: https://travis-ci.org/nestjs/nest 9 | 10 |

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

11 |

12 | NPM Version 13 | Package License 14 | NPM Downloads 15 | Travis 16 | Linux 17 | Coverage 18 | Gitter 19 | Backers on Open Collective 20 | Sponsors on Open Collective 21 | 22 | 23 |

24 | 26 | 27 | ## Description 28 | 29 | In this tutorial, we'll add JWT authentication to protect our RESTful endpoints from unauthorized access. 30 | 31 | 32 | > Read [Nest.js Tutorial: Build your First REST API CRUD App with TypeORM](https://www.techiediaries.com/nestjs-tutorial-rest-api-crud) 33 | > 34 | > [Nest.js Tutorial: JWT Authentication with Passport.js](https://www.techiediaries.com/nestjs-tutorial-jwt-authentication) 35 | 36 | > [Nest.js Tutorial: File Uploading with Multer and Serving Static Files in Nest](https://www.techiediaries.com/nestjs-upload-serve-static-file) 37 | 38 | ```bash 39 | $ git clone https://github.com/techiediaries/nestjs-upload-serve-file.git 40 | ``` 41 | 42 | ## Installation 43 | 44 | ```bash 45 | $ cd nestjs-upload-serve-file 46 | $ npm install 47 | ``` 48 | 49 | ## Running the app 50 | 51 | ```bash 52 | # development 53 | $ npm run start 54 | 55 | # watch mode 56 | $ npm run start:dev 57 | 58 | # incremental rebuild (webpack) 59 | $ npm run webpack 60 | $ npm run start:hmr 61 | 62 | # production mode 63 | $ npm run start:prod 64 | ``` 65 | 66 | ## Test 67 | 68 | ```bash 69 | # unit tests 70 | $ npm run test 71 | 72 | # e2e tests 73 | $ npm run test:e2e 74 | 75 | # test coverage 76 | $ npm run test:cov 77 | ``` 78 | 79 | 80 | ## License 81 | 82 | Nest is [MIT licensed](LICENSE). 83 | -------------------------------------------------------------------------------- /nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /nodemon-debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "node --inspect-brk -r ts-node/register src/main.ts" 6 | } -------------------------------------------------------------------------------- /nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "ts-node -r tsconfig-paths/register src/main.ts" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crud-app", 3 | "version": "0.0.0", 4 | "description": "description", 5 | "author": "", 6 | "license": "MIT", 7 | "scripts": { 8 | "format": "prettier --write \"src/**/*.ts\"", 9 | "start": "ts-node -r tsconfig-paths/register src/main.ts", 10 | "start:dev": "nodemon", 11 | "start:debug": "nodemon --config nodemon-debug.json", 12 | "prestart:prod": "rimraf dist && tsc", 13 | "start:prod": "node dist/main.js", 14 | "start:hmr": "node dist/server", 15 | "lint": "tslint -p tsconfig.json -c tslint.json", 16 | "test": "jest", 17 | "test:watch": "jest --watch", 18 | "test:cov": "jest --coverage", 19 | "test:e2e": "jest --config ./test/jest-e2e.json", 20 | "webpack": "webpack --config webpack.config.js" 21 | }, 22 | "dependencies": { 23 | "@nestjs/common": "^5.1.0", 24 | "@nestjs/core": "^5.1.0", 25 | "@nestjs/jwt": "^0.3.0", 26 | "@nestjs/typeorm": "^5.3.0", 27 | "passport-jwt": "^4.0.0", 28 | "reflect-metadata": "^0.1.12", 29 | "rxjs": "^6.2.2", 30 | "sqlite3": "^4.0.6", 31 | "typeorm": "^0.2.14", 32 | "typescript": "^3.0.1" 33 | }, 34 | "devDependencies": { 35 | "@nestjs/testing": "^5.1.0", 36 | "@types/express": "^4.16.0", 37 | "@types/jest": "^23.3.1", 38 | "@types/node": "^10.7.1", 39 | "@types/supertest": "^2.0.5", 40 | "jest": "^23.5.0", 41 | "nodemon": "^1.18.3", 42 | "prettier": "^1.14.2", 43 | "rimraf": "^2.6.2", 44 | "supertest": "^3.1.0", 45 | "ts-jest": "^23.1.3", 46 | "ts-loader": "^4.4.2", 47 | "ts-node": "^7.0.1", 48 | "tsconfig-paths": "^3.5.0", 49 | "tslint": "5.11.0", 50 | "webpack": "^4.16.5", 51 | "webpack-cli": "^3.1.0", 52 | "webpack-node-externals": "^1.7.2" 53 | }, 54 | "jest": { 55 | "moduleFileExtensions": [ 56 | "js", 57 | "json", 58 | "ts" 59 | ], 60 | "rootDir": "src", 61 | "testRegex": ".spec.ts$", 62 | "transform": { 63 | "^.+\\.(t|j)s$": "ts-jest" 64 | }, 65 | "coverageDirectory": "../coverage", 66 | "testEnvironment": "node" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import { AppController } from './app.controller'; 4 | import { AppService } from './app.service'; 5 | 6 | describe('AppController', () => { 7 | let app: TestingModule; 8 | 9 | beforeAll(async () => { 10 | app = await Test.createTestingModule({ 11 | controllers: [AppController], 12 | providers: [AppService], 13 | }).compile(); 14 | }); 15 | 16 | describe('root', () => { 17 | it('should return "Hello World!"', () => { 18 | const appController = app.get(AppController); 19 | expect(appController.root()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Get, Controller } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | root(): string { 10 | return this.appService.root(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { ContactsModule } from './contacts/contacts.module'; 5 | import { TypeOrmModule } from '@nestjs/typeorm'; 6 | import { AuthModule } from './auth/auth.module'; 7 | 8 | @Module({ 9 | imports: [ContactsModule, 10 | TypeOrmModule.forRoot({ 11 | type: 'sqlite', 12 | database: 'db', 13 | entities: [__dirname + '/**/*.entity{.ts,.js}'], 14 | synchronize: true, 15 | }), AuthModule,], 16 | controllers: [AppController], 17 | providers: [AppService], 18 | }) 19 | export class AppModule {} 20 | -------------------------------------------------------------------------------- /src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | root(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { TypeOrmModule } from '@nestjs/typeorm'; 3 | import { User } from './user.entity'; 4 | import { UserService } from './user.service'; 5 | import { JwtModule } from '@nestjs/jwt'; 6 | import { AuthService } from './auth.service'; 7 | import { AuthController } from './auth/auth.controller'; 8 | 9 | @Module({ 10 | imports: [TypeOrmModule.forFeature([User]), 11 | JwtModule.register({ 12 | secretOrPrivateKey: 'secret12356789' 13 | }) 14 | ], 15 | providers: [UserService, AuthService], 16 | controllers: [AuthController] 17 | }) 18 | export class AuthModule { } 19 | -------------------------------------------------------------------------------- /src/auth/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AuthService } from './auth.service'; 3 | 4 | describe('AuthService', () => { 5 | let service: AuthService; 6 | beforeAll(async () => { 7 | const module: TestingModule = await Test.createTestingModule({ 8 | providers: [AuthService], 9 | }).compile(); 10 | service = module.get(AuthService); 11 | }); 12 | it('should be defined', () => { 13 | expect(service).toBeDefined(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { JwtService } from '@nestjs/jwt'; 3 | import { UserService } from './user.service'; 4 | import { User } from './user.entity'; 5 | 6 | @Injectable() 7 | export class AuthService { 8 | constructor( 9 | private readonly userService: UserService, 10 | private readonly jwtService: JwtService 11 | ) { } 12 | 13 | private async validate(userData: User): Promise { 14 | return await this.userService.findByEmail(userData.email); 15 | } 16 | 17 | public async login(user: User): Promise< any | { status: number }>{ 18 | return this.validate(user).then((userData)=>{ 19 | if(!userData){ 20 | return { status: 404 }; 21 | } 22 | let payload = `${userData.name}${userData.id}`; 23 | const accessToken = this.jwtService.sign(payload); 24 | 25 | return { 26 | expires_in: 3600, 27 | access_token: accessToken, 28 | user_id: payload, 29 | status: 200 30 | }; 31 | 32 | }); 33 | } 34 | 35 | public async register(user: User): Promise{ 36 | return this.userService.create(user) 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/auth/auth/auth.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AuthController } from './auth.controller'; 3 | 4 | describe('Auth Controller', () => { 5 | let module: TestingModule; 6 | beforeAll(async () => { 7 | module = await Test.createTestingModule({ 8 | controllers: [AuthController], 9 | }).compile(); 10 | }); 11 | it('should be defined', () => { 12 | const controller: AuthController = module.get(AuthController); 13 | expect(controller).toBeDefined(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/auth/auth/auth.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Post, Body, Param, Get, Res } from '@nestjs/common'; 2 | import { AuthService } from '../auth.service'; 3 | import { User } from '../user.entity'; 4 | import { UserService } from '../user.service'; 5 | import { UseInterceptors, FileInterceptor, UploadedFile } from '@nestjs/common'; 6 | import { diskStorage } from 'multer'; 7 | import { extname } from 'path'; 8 | 9 | @Controller('auth') 10 | export class AuthController { 11 | SERVER_URL: string = "http://localhost:3000/"; 12 | 13 | constructor(private readonly authService: AuthService, private userService: UserService) { } 14 | 15 | @Post('login') 16 | async login(@Body() user: User): Promise { 17 | return this.authService.login(user); 18 | } 19 | 20 | @Post('register') 21 | async register(@Body() user: User): Promise { 22 | return this.authService.register(user); 23 | } 24 | 25 | 26 | @Post(':userid/avatar') 27 | @UseInterceptors(FileInterceptor('file', 28 | { 29 | storage: diskStorage({ 30 | destination: './avatars', 31 | 32 | filename: (req, file, cb) => { 33 | const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join('') 34 | return cb(null, `${randomName}${extname(file.originalname)}`) 35 | } 36 | }) 37 | } 38 | ) 39 | ) 40 | uploadAvatar(@Param('userid') userId, @UploadedFile() file) { 41 | 42 | this.userService.setAvatar(Number(userId), `${this.SERVER_URL}${file.path}`); 43 | 44 | } 45 | 46 | @Get('avatars/:fileId') 47 | async serveAvatar(@Param('fileId') fileId, @Res() res): Promise { 48 | res.sendFile(fileId, { root: 'avatars' }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/auth/user.entity.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Column, PrimaryGeneratedColumn,BeforeInsert } from 'typeorm'; 2 | import * as crypto from 'crypto'; 3 | 4 | @Entity() 5 | export class User { 6 | @PrimaryGeneratedColumn() 7 | id: number; 8 | 9 | @Column() 10 | name: string; 11 | 12 | @Column({default: ''}) 13 | avatar: string; 14 | 15 | @Column() 16 | email: string; 17 | 18 | @BeforeInsert() 19 | hashPassword() { 20 | this.password = crypto.createHmac('sha256', this.password).digest('hex'); 21 | } 22 | @Column() 23 | password: string; 24 | } -------------------------------------------------------------------------------- /src/auth/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { UserService } from './user.service'; 3 | 4 | describe('UserService', () => { 5 | let service: UserService; 6 | beforeAll(async () => { 7 | const module: TestingModule = await Test.createTestingModule({ 8 | providers: [UserService], 9 | }).compile(); 10 | service = module.get(UserService); 11 | }); 12 | it('should be defined', () => { 13 | expect(service).toBeDefined(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/auth/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Repository } from 'typeorm'; 3 | import { InjectRepository } from '@nestjs/typeorm' 4 | import { User } from './user.entity'; 5 | 6 | 7 | @Injectable() 8 | export class UserService { 9 | constructor( 10 | @InjectRepository(User) 11 | private userRepository: Repository, 12 | ) { } 13 | 14 | async findByEmail(email: string): Promise { 15 | return await this.userRepository.findOne({ 16 | where: { 17 | email: email, 18 | } 19 | }); 20 | } 21 | 22 | async findById(id: number): Promise { 23 | return await this.userRepository.findOne({ 24 | where: { 25 | id: id, 26 | } 27 | }); 28 | } 29 | 30 | async create(user: User): Promise { 31 | return await this.userRepository.save(user); 32 | } 33 | public async setAvatar(userId: number, avatarUrl: string){ 34 | this.userRepository.update(userId, {avatar: avatarUrl}); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/contacts/contact.entity.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; 2 | 3 | @Entity() 4 | export class Contact { 5 | @PrimaryGeneratedColumn() 6 | id: number; 7 | 8 | @Column() 9 | firstName: string; 10 | 11 | @Column() 12 | lastName: string; 13 | 14 | @Column() 15 | email: string; 16 | 17 | @Column() 18 | phone: string; 19 | 20 | @Column() 21 | city: string; 22 | 23 | @Column() 24 | country: string; 25 | } -------------------------------------------------------------------------------- /src/contacts/contacts.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ContactsService } from './contacts.service'; 3 | import { ContactsController } from './contacts/contacts.controller'; 4 | import { TypeOrmModule } from '@nestjs/typeorm'; 5 | import { Contact } from './contact.entity'; 6 | 7 | @Module({ 8 | imports: [ 9 | TypeOrmModule.forFeature([Contact]), 10 | ], 11 | providers: [ContactsService], 12 | controllers: [ContactsController] 13 | }) 14 | export class ContactsModule {} 15 | -------------------------------------------------------------------------------- /src/contacts/contacts.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { ContactsService } from './contacts.service'; 3 | 4 | describe('ContactsService', () => { 5 | let service: ContactsService; 6 | beforeAll(async () => { 7 | const module: TestingModule = await Test.createTestingModule({ 8 | providers: [ContactsService], 9 | }).compile(); 10 | service = module.get(ContactsService); 11 | }); 12 | it('should be defined', () => { 13 | expect(service).toBeDefined(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/contacts/contacts.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Repository, UpdateResult, DeleteResult } from 'typeorm'; 3 | import { InjectRepository } from '@nestjs/typeorm'; 4 | import { Contact } from './contact.entity'; 5 | 6 | @Injectable() 7 | export class ContactsService { 8 | constructor( 9 | @InjectRepository(Contact) 10 | private contactRepository: Repository, 11 | ) { } 12 | async findAll(): Promise { 13 | return await this.contactRepository.find(); 14 | } 15 | 16 | async create(contact: Contact): Promise { 17 | return await this.contactRepository.save(contact); 18 | } 19 | 20 | async update(contact: Contact): Promise { 21 | 22 | return await this.contactRepository.update(contact.id,contact); 23 | } 24 | 25 | async delete(id): Promise { 26 | return await this.contactRepository.delete(id); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/contacts/contacts/contacts.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { ContactsController } from './contacts.controller'; 3 | 4 | describe('Contacts Controller', () => { 5 | let module: TestingModule; 6 | beforeAll(async () => { 7 | module = await Test.createTestingModule({ 8 | controllers: [ContactsController], 9 | }).compile(); 10 | }); 11 | it('should be defined', () => { 12 | const controller: ContactsController = module.get(ContactsController); 13 | expect(controller).toBeDefined(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/contacts/contacts/contacts.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Post,Put, Delete, Body, Param } from '@nestjs/common'; 2 | import { Contact } from '../contact.entity'; 3 | import { ContactsService } from '../contacts.service'; 4 | 5 | @Controller('contacts') 6 | export class ContactsController { 7 | constructor(private contactsService: ContactsService){} 8 | 9 | @Get() 10 | index(): Promise { 11 | return this.contactsService.findAll(); 12 | } 13 | 14 | @Post('create') 15 | async create(@Body() contactData: Contact): Promise { 16 | return this.contactsService.create(contactData); 17 | } 18 | 19 | @Put(':id/update') 20 | async update(@Param('id') id, @Body() contactData: Contact): Promise { 21 | contactData.id = Number(id); 22 | console.log('Update #' + contactData.id) 23 | return this.contactsService.update(contactData); 24 | } 25 | 26 | @Delete(':id/delete') 27 | async delete(@Param('id') id): Promise { 28 | return this.contactsService.delete(id); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main.hmr.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | declare const module: any; 5 | 6 | async function bootstrap() { 7 | const app = await NestFactory.create(AppModule); 8 | await app.listen(3000); 9 | 10 | if (module.hot) { 11 | module.hot.accept(); 12 | module.hot.dispose(() => app.close()); 13 | } 14 | } 15 | bootstrap(); 16 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { INestApplication } from '@nestjs/common'; 2 | import { Test } from '@nestjs/testing'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeAll(async () => { 10 | const moduleFixture = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "noImplicitAny": false, 6 | "removeComments": true, 7 | "noLib": false, 8 | "allowSyntheticDefaultImports": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es6", 12 | "sourceMap": true, 13 | "outDir": "./dist", 14 | "baseUrl": "./src" 15 | }, 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | "node_modules", 21 | "**/*.spec.ts" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tsconfig.json", 3 | "compilerOptions": { 4 | "types": ["jest", "node"] 5 | }, 6 | "include": ["**/*.spec.ts", "**/*.d.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": { 7 | "no-unused-expression": true 8 | }, 9 | "rules": { 10 | "eofline": false, 11 | "quotemark": [ 12 | true, 13 | "single" 14 | ], 15 | "indent": false, 16 | "member-access": [ 17 | false 18 | ], 19 | "ordered-imports": [ 20 | false 21 | ], 22 | "max-line-length": [ 23 | true, 24 | 150 25 | ], 26 | "member-ordering": [ 27 | false 28 | ], 29 | "curly": false, 30 | "interface-name": [ 31 | false 32 | ], 33 | "array-type": [ 34 | false 35 | ], 36 | "no-empty-interface": false, 37 | "no-empty": false, 38 | "arrow-parens": false, 39 | "object-literal-sort-keys": false, 40 | "no-unused-expression": false, 41 | "max-classes-per-file": [ 42 | false 43 | ], 44 | "variable-name": [ 45 | false 46 | ], 47 | "one-line": [ 48 | false 49 | ], 50 | "one-variable-per-declaration": [ 51 | false 52 | ] 53 | }, 54 | "rulesDirectory": [] 55 | } 56 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const path = require('path'); 3 | const nodeExternals = require('webpack-node-externals'); 4 | 5 | module.exports = { 6 | entry: ['webpack/hot/poll?1000', './src/main.hmr.ts'], 7 | watch: true, 8 | target: 'node', 9 | externals: [ 10 | nodeExternals({ 11 | whitelist: ['webpack/hot/poll?1000'], 12 | }), 13 | ], 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.tsx?$/, 18 | use: 'ts-loader', 19 | exclude: /node_modules/, 20 | }, 21 | ], 22 | }, 23 | mode: "development", 24 | resolve: { 25 | extensions: ['.tsx', '.ts', '.js'], 26 | }, 27 | plugins: [ 28 | new webpack.HotModuleReplacementPlugin(), 29 | ], 30 | output: { 31 | path: path.join(__dirname, 'dist'), 32 | filename: 'server.js', 33 | }, 34 | }; 35 | --------------------------------------------------------------------------------