3.0.12 • Published 5 months ago

@webundsoehne/nestjs-util-restful v3.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

@webundsoehne/nestjs-util-restful

Version Downloads/week Dependencies semantic-release

Description

This is a collection of useful modules on creating a Nest project. Mostly all of this modules are used by the in-house boilerplate of Web & Söhne.

Modules

Interceptors

Cache-Lifetime

The interceptor sets the cache-lifetime information of the response as it was configured. The configuration depends normally by project and environment.

It will add a function to the request state request.state.setCacheLifetime(), with that you can set a customize lifetime for each request.

Usage

import { RequestProfilerInterceptor } from '@webundsoehne/nestjs-util'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestProfilerInterceptor
    }
  ]
})
class ServerModule implements NestModule {}

setCacheLifetime()

This function takes 2 parameters, where the second one is optional.

NameTypeOptionalDescription
lifetimeNumberfalseThe lifetime of the cache in seconds
useExpiresHeaderBooleantrueIf true the expiresHeader header will be set, otherwise the cacheControlHeader, be default it uses the configured value

Configuration

The default values only exists in out skeleton project.

KeyTypeDefaultDescription
cacheLifetime.defaultExpiresHeaderBooleanfalseIf true the expiresHeader header will be set, otherwise the cacheControlHeader
cacheLifetime.defaultLifetimeNumber0This value may set a default cache lifetime, if there was not set any before
cacheLifetime.expiresHeaderString'Expires'The header key for the expiresHeader
cacheLifetime.cacheControlHeaderString'Cache-control'The header key for the cacheControlHeader

Request-Profiler

On debug logger level the request profile informs you when an request got started and when it was finished. It also logs down the information, how many seconds the request took.

Usage

import { RequestProfilerInterceptor } from '@webundsoehne/nestjs-util'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestProfilerInterceptor
    }
  ]
})
class ServerModule implements NestModule {}

Example

[2020-01-01T12:00:00.000Z] [debug] [RequestProfilerInterceptor] - GET /v1/hello/world starting
[2020-01-01T12:00:00.025Z] [debug] [RequestProfilerInterceptor] - GET /v1/hello/world finished - took: 0.0250 sec

Providers

Swagger

Automatically creates a Swagger documentation out of your controllers. For detailed information about the how-to, take a deeper look at the Nest documentation.

Usage

import { SwaggerService } from '@webundsoehne/nestjs-util'

const app = await NestFactory.create<INestApplication>(ServerModule, new FastifyAdapter())
SwaggerService.enable(app, options)

Parameters

NameRequiredTypeDescription
apptrueINestApplicationThe Nest application on which the documentation should be created
optionsfalseSwaggerOptionsOptions for customize the default created document
configfalseSwaggerConfigStandard configuration, which are required for creating a documentation

Types

SwaggerOptions

NameRequiredTypeDescription
customizefalseFunctionThis function takes an DocumentBuilder modifies and returns it

SwaggerConfig

NameRequiredTypeDescription
useHttpstrueBooleanIf the API is behind SSL encryption
basePathtrueStringThe base-path of the API
pathtrueStringThe sub-path to reach the API
titletrueStringThe name of the API or the customer
descriptiontrueStringA description for the whole API

Modules

Internal

This is a NestJS controller module for internal API endpoints, which can simply be added to each project. The controller provides you 2 endpoints /status and /changelog.

Usage

import { InternalModule } from '@webundsoehne/nestjs-util'

@Module({
  imports: [InternalModule]
})
class ServerModule implements NestModule {
  async configure(): Promise<any> {
    await setEnvironmentVariables()
  }
}

Configuration

KeyTypeDefaultDescription
misc.changelogFileString'CHANGELOG.md'The filepath of the project's changelog information
misc.lastUpdateFileString'.last-update'The filepath of the projects's last update file

Status

The status endpoint returns the current API version set during the process environment and the last modification of the .last-update in your root directory. The version will be set with the util function setEnvironmentVariables() read from package.json and the file will normally be generated/modified during the deployment process. You may change this value with the misc.lastUpdateFile configuration.

Changelog

This endpoint simply reads and response the CHANGELOG.md from your root directory. You can change the filepath with the configuration value misc.changelogFile.

Stay in touch

3.0.12

7 months ago

3.0.10

10 months ago

3.0.11

10 months ago

3.0.13-beta.4

5 months ago

3.0.13-beta.5

5 months ago

3.0.13-beta.6

5 months ago

3.0.13-beta.1

5 months ago

3.0.13-beta.2

5 months ago

3.0.13-beta.3

5 months ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.8

1 year ago

3.0.7

1 year ago

3.0.6

1 year ago

3.0.5

1 year ago

3.0.0

1 year ago

3.0.4-beta.1

1 year ago

3.0.0-beta.1

1 year ago

3.0.0-beta.3

1 year ago

3.0.0-beta.2

1 year ago

3.0.0-beta.4

1 year ago

3.0.9

11 months ago

1.4.6

2 years ago

1.2.3-beta.1

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

1 year ago

2.0.4

2 years ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.2-beta.1

2 years ago

2.0.0-beta.2

2 years ago

2.0.0-beta.1

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.0-beta.3

2 years ago

1.3.2-beta.1

2 years ago

1.3.0-beta.1

2 years ago

1.3.2-beta.2

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.2.0-beta.2

2 years ago

1.2.0-beta.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago