Skip to content

Commit

Permalink
feat(readme): readme
Browse files Browse the repository at this point in the history
readme
  • Loading branch information
PavloYakun committed Oct 1, 2020
1 parent 63334d5 commit cf0ea88
Show file tree
Hide file tree
Showing 70 changed files with 801 additions and 273 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![onix](https://img.shields.io/badge/onix-systems-blue.svg)

> Node.js Nest.js API with TypeScript 3. Supports MongoDB
> Node.js Nest.js API. Supports MongoDB, Mysql, Redis ;)
## Description
This generator will help you to build your own Nest.js Mongodb API using TypeScript 3.
Expand Down Expand Up @@ -132,7 +132,7 @@ npm test
In root folder you can find `.env`. You can use this config or change it for your purposes.

## Deploy
- Heroku
- Heroku (http://heroku.com)
- npm run deploy:heroku
- NOTICES
- Check all urls to dbs if they are true, they must connect to dbs which located at them own servers like mongodb on Mlab
Expand All @@ -151,6 +151,13 @@ http://localhost:3000/api
### Oauth2 auth
![Alt Text3](https://media.giphy.com/media/RiWDyLQwXaJXu972SM/giphy.gif)
- When you go by http://localhost:3000/google route, google'll ask you to authorize into your account. After successfully sign in to your account you will be redirected to http://localhost:3000/google/redirect route

## Clinic Benchmark
### Graph
![Clinic Benchmark](https://lh3.googleusercontent.com/ZE9nbA3Ydkqn1Pr7YyoC400Dw4dxAvML-JBaGFk_2tWw5qQWm-oyA0toBC8Tu-lGOrqpT3ElnR17gLIFPc7bqqESBoBB_r6vEhfbaRP8vIq2u9Zq6Zz5s3cHs9OMk-Kjbt9atIZReKohT_8ne48irv3kMkxpGgLxV0OrBibaHM2N8nglUCbnGB_TI11RfqjrnKA_0pk2cf9BtgexbiB24skvhcAssAWJb3VX7N8DLEhgR75XyOuVMP0RgxvshM0owlSufAm4iDvFu0hGQtIh_zwd5H0zu8uvQDjYHA9uukr0Xqn4O8B8dMgp5wYgAA1IOkRcZuRlQEahxDEkse0NHzppL1clJvFXAqNJ8jOJ7xxgOg7o07eiaIdqZ_5d4-pyAjTw5O1eWICsFyUl6cQZxWPjc6-jnHbW4czTudjfwtHUBc8tp1q5BOjQmpZ3X7qiwaDEurkVBF6jvP8cqrouxabJBQkI6WwK05GaOs8KewZoU6EcMgo0cuiC3YHbe3AYygXmu3hbf2eYLod8WblKZ57SM72MDOIhc5_UIt9pNT8YW_0QDNScFoJTGGJY4dvqI312VjRQLftU_NG0Pb2cuqR4Rc6Byc6DprFxnhPriaQ0k0vLaWDJkhjWBoFagHMnS0z_lsciycB6GoThPNMRzsmyQE7yIKI0BehltMLTynDgfqhlOhNExFZjpi1D-g=w1622-h912-no?authuser=0)
### Graphics
![Graphics](https://lh3.googleusercontent.com/wTXv1mVlL0WINon8d-m6poo3vwZMI3sTe0fpGUys7xodHN7sdwGN3eEeDbW8tu_Vyfi8rXbh5UpAZSdgAkNso2Wf7zk4MFprxgJYNTSSZmpO3pgmsI00nGE45gwG3OgVTL6zLjIel4KFdy5eJMneg_OPEwiALh5d6sAMSGDczb5VHlJ1pMK6GuzywYRKcUfjo07-q8kNBozf1q6ZIpsie8eaB5mMOFaWrp__twFS9z25_Nxrlz7abCG-yiGd2v_GFTM_8BbpbfMJUTZspQVVPgj9QpXqx00huVd82QVxjAD0xYTgSbzRbiYRWlITzZ98XToTlPenA6ddZRrj1uZm8q2LdeBYHg0yIFHjzihL0CTLwKULvpOSPUdUOAs74XgypKcI2IyPJHThBJ6cLOGOYh69fCboZDgYaPDsMjr1A0vxaDOjouoOkLSieGigsZBK796PfV-JsGmK9RA2uHXcUQBPF-U2v7to9sgie2FwB283vv_M1iXAe437zohSyMQqOS7F0gNU_6orWRXctCRN8N6lPL_A6n1Cl5qSOzxtACCg8VRf1znXFiuXjfBemntJ9prOcdYi0r0ePrfEMg2EpascJG2CvxzZn0sWCGfxUuuOa2iuKvMvGVbxR4QCeF5jCymM48suARom3kOQ6tLKbzS5Qh8QUdm3eQgpomXq2KZVIT_8Zu2rlUAESgm_PQ=w1622-h912-no?authuser=0)

## Getting To Know Yeoman

* Yeoman has a heart of gold.
Expand Down
12 changes: 12 additions & 0 deletions generators/app/questions/additionalAuthQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ module.exports = {
message: 'Type your expiration time for access token',
default: '1d',
},
{
type: 'input',
name: 'accessTokenSecret',
message: 'Type your secret for access token',
default: '283f01ccce922bcc2399e7f8ded981285963cec349daba382eb633c1b3a5f282',
},
{
type: 'input',
name: 'refreshTokenSecret',
message: 'Type your secret for refresh token',
default: 'c15476aec025be7a094f97aac6eba4f69268e706e603f9e1ec4d815396318c86',
},
],
passportLocal: [
{
Expand Down
9 changes: 9 additions & 0 deletions generators/app/questions/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = [
{
type: 'list',
name: 'deploy:heroku',
message: 'Do you want to have a possibillity to deploy on heroku?',
default: 'No',
choices: ['Yes', 'No'],
},
]
2 changes: 2 additions & 0 deletions generators/app/questions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const identifier = require('./identifier');
const description = require('./description');
const docker = require('./docker');
const db = require('./db');
const deploy = require('./deploy');

module.exports = {
packageManager,
Expand All @@ -18,4 +19,5 @@ module.exports = {
description,
docker,
db,
deploy,
};
6 changes: 5 additions & 1 deletion generators/app/steps/prompting.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ module.exports = {
askAboutDatabase() {
askQuestions.call(this, 'Database', questions.db, this.async());
},

askWouldHeLikeDocker() {
askQuestions.call(this, 'Docker', questions.docker, this.async());
},

askWouldHeLikeToDeployOnHeroku() {
askQuestions.call(this, 'Deploy on heroku', questions.deploy, this.async());
},

askAppIdentifier() {
askQuestions.call(
this,
Expand Down
13 changes: 8 additions & 5 deletions generators/app/steps/writing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ module.exports = function() {
this.destinationPath(`${this.answers.identifier}/package-lock.json`),
payload,
);
this.fs.copyTpl(
this.templatePath(path.join('./deployHeroku.sh')),
this.destinationPath(`${this.answers.identifier}/deployHeroku.sh`),
payload,
);
this.fs.copyTpl(
this.templatePath(path.join('./README.md')),
this.destinationPath(`${this.answers.identifier}/README.md`),
Expand Down Expand Up @@ -82,4 +77,12 @@ module.exports = function() {
this.destinationPath(`${this.answers.identifier}/.prettierrc`),
payload,
);

if (answers['deploy:heroku'] === 'Yes') {
this.fs.copyTpl(
this.templatePath(path.join('./deploy-heroku.sh')),
this.destinationPath(`${this.answers.identifier}/deploy-heroku.sh`),
payload,
);
}
};
4 changes: 2 additions & 2 deletions generators/app/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![onix](https://img.shields.io/badge/onix-systems-blue.svg)

> Node.js Nest.js API with TypeScript 3. Supports MongoDB
> Node.js Nest.js API. Supports MongoDB, Mysql, Redis ;)
## Description
This generator will help you to build your own Nest.js Mongodb API using TypeScript 3.
Expand Down Expand Up @@ -132,7 +132,7 @@ npm test
In root folder you can find `.env`. You can use this config or change it for your purposes.

## Deploy
- Heroku
- Heroku (http://heroku.com)
- npm run deploy:heroku
- NOTICES
- Check all urls to dbs if they are true, they must connect to dbs which located at them own servers like mongodb on Mlab
Expand Down
File renamed without changes.
40 changes: 22 additions & 18 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
"deploy:heroku": "chmod +x ./deployHeroku.sh && sudo ./deployHeroku.sh"
},
"dependencies": {
"@nestjs/config": "^0.5.0",
"@nestjs/common": "^7.4.2",
"@nestjs/core": "^7.4.2",
"@nestjs/platform-express": "^7.4.2",
"@nestjs/testing": "^7.4.2",
"bcrypt": "^5.0.0",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"express": "^4.17.1",
"husky": "^4.2.5",
"module-alias": "^2.2.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"@nestjs/swagger": "^4.6.0",
"swagger-ui-express": "^4.1.4",
"open": "^7.2.1"
"@nestjs/config": "0.5.0",
"@nestjs/common": "7.4.2",
"@nestjs/core": "7.4.2",
"@nestjs/platform-express": "7.4.2",
"@nestjs/testing": "7.4.2",
"bcrypt": "5.0.0",
"class-transformer": "0.2.3",
"class-validator": "0.12.2",
"express": "4.17.1",
"husky": "4.2.5",
"module-alias": "2.2.2",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"rxjs": "6.5.4",
"@nestjs/swagger": "4.6.0",
"swagger-ui-express": "4.1.4",
"open": "7.2.1"
},
"devDependencies": {
"@nestjs/cli": "7.0.0",
Expand All @@ -47,6 +47,7 @@
"@types/jest": "25.2.3",
"@types/node": "13.9.1",
"@types/supertest": "2.0.8",
"@types/bcrypt": "3.0.0",
"@typescript-eslint/eslint-plugin": "3.0.2",
"@typescript-eslint/parser": "3.0.2",
"cz-conventional-changelog": "3.2.0",
Expand Down Expand Up @@ -94,7 +95,10 @@
"@guards": "./dist/guards",
"@interfaces": "./dist/interfaces",
"@pipes": "./dist/pipes",
"@dto": "./dist/dto"
"@dto": "./dist/dto",
"@responses": "./dist/responses",
"@interceptors": "./dist/interceptors",
"@decorators": "./dist/decorators"
},
"husky": {
"hooks": {
Expand Down
6 changes: 5 additions & 1 deletion generators/app/templates/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"strict": true,
"paths": {
"@filters/*": ["./src/filters/*"],
"@guards/*": ["./src/guards/*"],
"@interfaces/*": ["./src/interfaces/*"],
"@shared/*": ["./src/components/shared/*"],
"@components/*": ["./src/components/*"],
"@pipes/*": ["./src/pipes/*"],
"@dto/*": ["./src/dto/*"]
"@dto/*": ["./src/dto/*"],
"@responses/*": ["./src/responses/*"],
"@interceptors/*": ["./src/interceptors/*"],
"@decorators/*": ["./src/decorators/*"]
}
}
}
23 changes: 22 additions & 1 deletion generators/auth/steps/writing.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,28 @@ module.exports = function() {
payload,
);
}

if (fs.existsSync(`${fullPathToAuthFolder}/src/responses`)) {
this.fs.copyTpl(
this.templatePath(`${authFolder}/src/responses`),
this.destinationPath(`${answers.identifier}/src/responses`),
payload,
);
}
if (fs.existsSync(`${fullPathToAuthFolder}/src/interceptors`)) {
this.fs.copyTpl(
this.templatePath(`${authFolder}/src/interceptors`),
this.destinationPath(`${answers.identifier}/src/interceptors`),
payload,
);
}
if (fs.existsSync(`${fullPathToAuthFolder}/src/decorators`)) {
this.fs.copyTpl(
this.templatePath(`${authFolder}/src/decorators`),
this.destinationPath(`${answers.identifier}/src/decorators`),
payload,
);
}

// DOCKER
if (answers.wantedDocker.toLowerCase() === 'yes') {
this.fs.copyTpl(
Expand Down
12 changes: 12 additions & 0 deletions generators/auth/templates/mongodb/jwt/_.env
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
SERVER_PORT=<%= config.serverPort %>

<% if(config.wantedDocker === 'Yes') { %>
MONGODB_URL=mongodb://mongodb:27017/app
REDIS_URL=redis://redis:6379
<% } %>

<% if(config.wantedDocker === 'No') { %>
MONGODB_URL=mongodb://localhost:27017/app
REDIS_URL=redis://localhost:6379
<% } %>


2 changes: 1 addition & 1 deletion generators/auth/templates/mongodb/jwt/src/_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import AppModule from './components/app/app.module';
import AppService from './components/app/app.service';

import AllExceptionsFilter from './filters/allExceptions.filter';
import AllExceptionsFilter from './filters/all-exceptions.filter';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AppService from '@components/app/app.service';
import { ApiOkResponse } from '@nestjs/swagger';
import { Controller, Get } from '@nestjs/common';

@Controller()
export default class AppController {
constructor(private readonly appService: AppService) {}

@ApiOkResponse({ description: 'Returns you Hello world!' })
@Get()
sayHello(): string {
return this.appService.getHello();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { MongooseModule } from '@nestjs/mongoose';
import AuthModule from '@components/auth/auth.module';
import UsersModule from '@components/users/users.module';

import AppController from './app.controller';
import AppService from './app.service';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
MongooseModule.forRoot('mongodb://mongodb:27017/app', {
MongooseModule.forRoot(process.env.MONGODB_URL as string, {
// automatically try to reconnect when it loses connection
autoReconnect: true,
useCreateIndex: true,
Expand All @@ -27,18 +28,22 @@ import AppService from './app.service';
useUnifiedTopology: true,
}),
RedisModule.register({
url: 'redis://redis:6379',
url: process.env.REDIS_URL,
onClientReady: async (client): Promise<void> => {
client.on('error', console.error);
client.on('ready', () => console.log('redis is running on 6379 port'));
client.on('restart', () => console.log('attempt to restart the redis server'));
client.on('ready', () => {
console.log('redis is running on 6379 port');
});
client.on('restart', () => {
console.log('attempt to restart the redis server');
});
},
reconnectOnError: (): boolean => true,
}),
AuthModule,
UsersModule,
],
controllers: [],
controllers: [AppController],
providers: [AppService],
})
export default class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default class AppService {

await open(url);
}

getHello(): string {
return 'Hello world!';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from '@nestjs/common';

const DtoFactory = {
wrap<T>(responseDto: T): Type<unknown> {
class SuccessResponseDto {
@ApiProperty({ type: String })
public message: string = '';

@ApiProperty({ type: responseDto })
public data: T | null = null;
}

return SuccessResponseDto;
},
};

const AppUtils = {
DtoFactory,
};

export default AppUtils;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const authConstants = {
jwt: {
secret: '<%= config.jwtSecret %>',
expirationTime: {
accessToken: '<%= config.refreshTokenExpirationTime %>',
refreshToken: '<%= config.accessTokenExpirationTime %>',
},
secrets: {
accessToken: '<%= config.accessTokenSecret %>',
refreshToken: '<%= config.refreshTokenSecret %>',
},
},
redis: {
expirationTime: {
jwt: {
accessToken: 86400, // 1d
refreshToken: 604800, // 7d
},
},
},
};

export default authConstants;
Loading

0 comments on commit cf0ea88

Please sign in to comment.