Skip to content

Commit 0898de3

Browse files
committed
chore:
- update README and configuration examples; - redact sensitive headers;
1 parent 0bb8972 commit 0898de3

File tree

4 files changed

+110
-107
lines changed

4 files changed

+110
-107
lines changed

README.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ By default, the server will log the request and response to console. This behavi
8787

8888
By default, the server will log the request body and headers. These behaviors can be disabled by setting the `app.disableLogRequestBody` or `app.disableLogRequestHeaders` to `true`.
8989

90+
> **Sensitive headers**
91+
>
92+
> If you want to redact sensitive headers from the logs, you can set the `fastify.logger.redact` option in the config.
93+
9094
### Send request id header
9195

9296
By default, the server will send a `Request-Id` header to the client. This behavior can be disabled by setting the `app.disableSendRequestIdHeader` to `true`.
@@ -132,40 +136,41 @@ By default, the server will log the API error(`throw new ApiError()`). This beha
132136
### Install
133137

134138
```bash
135-
npm install fastify-app js-yaml
139+
npm install fastify-app
136140
```
137141

138-
> The `js-yaml` can be omitted if you don't want to use a yaml config file.
139-
140142
### Create a config file
141143

142-
Create a `config.yaml` file in your project root with the following example:
143-
144-
```yaml
145-
server:
146-
host: 0.0.0.0
147-
port: 53004
148-
149-
fastify:
150-
disableRequestLogging: false
151-
bodyLimit: 52428800 #in bytes, 50Mb
152-
logger:
153-
redact:
154-
- "req.headers.authorization"
155-
156-
app:
157-
disableCors: false
158-
disableLogRequestBody: false
159-
disableLogRequestHeaders: false
160-
disableLogApiError: false
161-
disableSendRequestIdHeader: false
162-
disableApiErrorHandler: false
163-
internalServerErrorCode: 200
164-
disableHealthCheckRoutes: false
165-
healthCheckRoutesPrefix: "/health-check"
166-
enableHealthCheckShowsGitRev: false
167-
disableAddRequestState: false
168-
disableReplyHelperFunctions: false
144+
Create a `config.js` file in your project root with the following example:
145+
146+
```javascript
147+
export default {
148+
server: {
149+
host: '0.0.0.0',
150+
port: 63004,
151+
},
152+
fastify: {
153+
disableRequestLogging: false,
154+
bodyLimit: 52428800, // 50Mb
155+
logger: {
156+
redact: ['req.headers.authorization'],
157+
},
158+
},
159+
app: {
160+
disableCors: false,
161+
disableLogRequestBody: false,
162+
disableLogRequestHeaders: false,
163+
disableLogApiError: false,
164+
disableSendRequestIdHeader: false,
165+
disableApiErrorHandler: false,
166+
internalServerErrorCode: 200,
167+
disableHealthCheckRoutes: false,
168+
healthCheckRoutesPrefix: '/health-check',
169+
enableHealthCheckShowsGitRev: false,
170+
disableAddRequestState: false,
171+
disableReplyHelperFunctions: false,
172+
},
173+
};
169174
```
170175

171176
### Create your first API endpoint
@@ -212,11 +217,8 @@ Files with names starting with an underscore will not be registered to the fasti
212217
### Start the server (CommonJS)
213218
```javascript
214219
const {default:fastifyApp, init, start} = require('fastify-app');
215-
const { load } = require('js-yaml');
216-
const { readFileSync } = require('fs');
217-
const knex = require('knex');
218220

219-
const config = load(readFileSync('./config.yaml', 'utf8'));
221+
const config = require('./config.js');
220222

221223
;(async() => {
222224
await init(config); //after calling init(), the fastifyApp is an initialized fastify instance.
@@ -227,10 +229,7 @@ const config = load(readFileSync('./config.yaml', 'utf8'));
227229
### Start the server (ES module)
228230
```javascript
229231
import FastifyApp, {init, start, ApiError} from 'fastify-app';
230-
import { load } from 'js-yaml';
231-
import { readFileSync } from 'fs';
232-
233-
const config = load(readFileSync('./config.yaml', 'utf8'));
232+
import config from './config.js';
234233

235234
;(async() => {
236235
await init(config);

0 commit comments

Comments
 (0)