Skip to content

Commit 67d5998

Browse files
author
kamil.mysliwiec
committed
Alpha 20 update
1 parent e2666b7 commit 67d5998

83 files changed

Lines changed: 1126 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 1.0.0-ALPHA-20
2+
3+
- Microservices support (TCP & Redis transports)
4+
- NestRunner -> NestFactory,
5+
- Simplify application initialization & configuration

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ We want to create scalable, modern and easy to maintain applications. Nest helps
4747

4848
## Starter repos
4949

50-
- [TypeScript] (https://github.com/kamilmysliwiec/nest-typescript-starter)
51-
- [Babel] (https://github.com/kamilmysliwiec/nest-babel-starter/)
50+
- [TypeScript](https://github.com/kamilmysliwiec/nest-typescript-starter)
51+
- [Babel](https://github.com/kamilmysliwiec/nest-babel-starter/)
5252

5353
## Future
5454

example/app.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/math/microservice.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NestFactory } from '../../src/nest-factory';
2+
import { Transport } from '../../src/common/enums/transport.enum';
3+
import { MicroserviceModule } from './modules/microservice.module';
4+
5+
const app = NestFactory.createMicroservice(
6+
MicroserviceModule, { transport: Transport.TCP, port: 5667 }
7+
);
8+
app.listen(() => console.log('Microservice listen on port:', 5667 ));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Controller } from '../../../src/common/utils/controller.decorator';
2+
import { MessagePattern } from '../../../src/microservices/utils/pattern.decorator';
3+
4+
@Controller()
5+
export class MathController {
6+
7+
@MessagePattern({ command: 'add' })
8+
multiply(data, respond) {
9+
if (!data) {
10+
respond(new Error('Invalid arguments'));
11+
return;
12+
}
13+
const numbers = data.numbers || [];
14+
respond(null, numbers.reduce((a, b) => a + b));
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Module } from '../../../src/common/utils/module.decorator';
2+
import { MathController } from './math.controller';
3+
4+
@Module({
5+
controllers: [ MathController ]
6+
})
7+
export class MicroserviceModule {}

example/modules/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Module } from './../../src/';
22
import { UsersModule } from './users/users.module';
3+
import { ClientController } from './client/client.controller';
34

45
@Module({
5-
modules: [ UsersModule ]
6+
modules: [ UsersModule ],
7+
controllers: [ ClientController ]
68
})
79
export class ApplicationModule {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Controller } from '../../../src/common/utils/controller.decorator';
2+
import { Client } from '../../../src/microservices/utils/client.decorator';
3+
import { RequestMapping } from '../../../src/common/utils/request-mapping.decorator';
4+
import { ClientProxy } from '../../../src/microservices/client/client-proxy';
5+
import { Observable } from 'rxjs/Observable';
6+
import { Transport } from '../../../src/common/enums/transport.enum';
7+
import 'rxjs/add/operator/catch';
8+
9+
@Controller()
10+
export class ClientController {
11+
12+
@Client({ transport: Transport.TCP, port: 5667 })
13+
client: ClientProxy;
14+
15+
@RequestMapping({ path: 'client' })
16+
sendCommand() {
17+
this.client.send({ command: 'add' }, { numbers: [ 1, 2, 3 ] })
18+
.catch((err) => Observable.empty())
19+
.subscribe((val) => console.log(val))
20+
}
21+
}

example/modules/users/auth.middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UsersService } from "./users.service";
1+
import { UsersService } from './users.service';
22
import { HttpException } from '../../../src/core/exceptions/http-exception';
33
import { Middleware } from '../../../src/common/utils';
44
import { NestMiddleware } from '../../../src/core/middlewares/interfaces/nest-middleware.interface';
@@ -10,7 +10,7 @@ export class AuthMiddleware implements NestMiddleware {
1010

1111
resolve() {
1212
return (req, res, next) => {
13-
const userName = req.headers["x-access-token"];
13+
const userName = req.headers['x-access-token'];
1414
const users = this.usersService.getUsers();
1515

1616
const user = users.find((user) => user.name === userName);
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { SocketGateway } from '../../../src/socket/utils/socket-gateway.decorator';
1+
import { WebSocketGateway } from '../../../src/socket/utils/socket-gateway.decorator';
22
import { SubscribeMessage } from '../../../src/socket/utils/subscribe-message.decorator';
33
import { Subject } from 'rxjs/Subject';
44
import { GatewayServer } from '../../../src/socket/utils/gateway-server.decorator';
55

6-
@SocketGateway({ port: 2000 })
6+
@WebSocketGateway({ port: 2000 })
77
export class ChatGateway {
88
private msg$ = new Subject<any>();
99

10-
@GatewayServer
11-
server;
10+
@GatewayServer server;
1211

1312
get msgStream() {
1413
return this.msg$.asObservable();
@@ -19,4 +18,4 @@ export class ChatGateway {
1918
this.msg$.next({ client, data });
2019
}
2120

22-
}
21+
}

0 commit comments

Comments
 (0)