forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
kamil.mysliwiec
committed
May 23, 2017
1 parent
2f83052
commit db0d0cc
Showing
18 changed files
with
228 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { NestFactory } from './../src/'; | ||
import { NestFactory } from './../src/core'; | ||
import { ApplicationModule } from './modules/app.module'; | ||
import { Transport } from '../src/microservices/index'; | ||
|
||
const port = 3001; | ||
const app = NestFactory.create(ApplicationModule); | ||
|
||
app.init(); | ||
app.listen(port, (server) => { | ||
const microservice = app.connectMicroservice({ | ||
transport: Transport.TCP, | ||
port: 5667, | ||
}); | ||
microservice.listen(() => ({})); | ||
app.listen(port, () => { | ||
console.log('Application listen on port:', port); | ||
server.close(); | ||
process.exit(); | ||
//app.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import { MicroserviceConfiguration } from '@nestjs/microservices'; | ||
import { INestMicroservice } from './index'; | ||
|
||
export interface INestApplication { | ||
init(): void; | ||
listen(port: number, callback?: (server?) => void): void; | ||
listen(port: number, callback?: () => void); | ||
setGlobalPrefix(prefix: string): void; | ||
connectMicroservice(config: MicroserviceConfiguration): INestMicroservice; | ||
getMicroservices(): INestMicroservice[]; | ||
startAllMicroservices(callback: () => void): void; | ||
close(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export interface INestMicroservice { | ||
listen(callback: () => void); | ||
close(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { expect } from 'chai'; | ||
import { isUndefined, isFunction, isObject, isString, isConstructor, validatePath, isNil, isEmpty } from '../../utils/shared.utils'; | ||
|
||
describe('Shared utils', () => { | ||
describe('isUndefined', () => { | ||
it('should returns true when obj is undefined', () => { | ||
expect(isUndefined(undefined)).to.be.true; | ||
}); | ||
it('should returns false when object is not undefined', () => { | ||
expect(isUndefined({})).to.be.false; | ||
}); | ||
}); | ||
describe('isFunction', () => { | ||
it('should returns true when obj is function', () => { | ||
expect(isFunction(() => ({}))).to.be.true; | ||
}); | ||
it('should returns false when object is not function', () => { | ||
expect(isFunction(null)).to.be.false; | ||
}); | ||
}); | ||
describe('isObject', () => { | ||
it('should returns true when obj is object', () => { | ||
expect(isObject({})).to.be.true; | ||
}); | ||
it('should returns false when object is not object', () => { | ||
expect(isObject(3)).to.be.false; | ||
}); | ||
}); | ||
describe('isString', () => { | ||
it('should returns true when obj is string', () => { | ||
expect(isString('true')).to.be.true; | ||
}); | ||
it('should returns false when object is not string', () => { | ||
expect(isString(false)).to.be.false; | ||
}); | ||
}); | ||
describe('isConstructor', () => { | ||
it('should returns true when string is equal constructor', () => { | ||
expect(isConstructor('constructor')).to.be.true; | ||
}); | ||
it('should returns false when string is not equal constructor', () => { | ||
expect(isConstructor('nope')).to.be.false; | ||
}); | ||
}); | ||
describe('validatePath', () => { | ||
it('should returns validated path ("add / if not exists")', () => { | ||
expect(validatePath('nope')).to.be.eql('/nope'); | ||
}); | ||
it('should returns same path', () => { | ||
expect(validatePath('/nope')).to.be.eql('/nope'); | ||
}); | ||
}); | ||
describe('isNil', () => { | ||
it('should returns true when obj is undefined or null', () => { | ||
expect(isNil(undefined)).to.be.true; | ||
expect(isNil(null)).to.be.true; | ||
}); | ||
it('should returns false when object is not undefined and null', () => { | ||
expect(isNil('3')).to.be.false; | ||
}); | ||
}); | ||
describe('isEmpty', () => { | ||
it('should returns true when array is empty or not exists', () => { | ||
expect(isEmpty([])).to.be.true; | ||
expect(isEmpty(null)).to.be.true; | ||
}); | ||
it('should returns false when array is not empty', () => { | ||
expect(isEmpty([1, 2])).to.be.false; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const messages = { | ||
APPLICATION_START: `Starting Nest application...`, | ||
APPLICATION_READY: `Nest application is ready!`, | ||
MICROSERVICE_READY: `Nest microservice is ready!`, | ||
UNKNOWN_EXCEPTION_MESSAGE: 'Unknown exception', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect } from 'chai'; | ||
import { ApplicationConfig } from '../application-config'; | ||
|
||
describe('ApplicationConfig', () => { | ||
let appConfig: ApplicationConfig; | ||
|
||
beforeEach(() => { | ||
appConfig = new ApplicationConfig(); | ||
}); | ||
describe('globalPath', () => { | ||
it('should set global path', () => { | ||
const path = 'test'; | ||
appConfig.setGlobalPrefix(path); | ||
|
||
expect(appConfig.getGlobalPrefix()).to.be.eql(path); | ||
}); | ||
it('should has empty string as a global path by default', () => { | ||
expect(appConfig.getGlobalPrefix()).to.be.eql(''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.