Skip to content

Commit 48484c2

Browse files
committed
Add installation, typescript instructions to README.
1 parent 04cc027 commit 48484c2

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
# fastify-https-always
1+
# Fastify https-always Plugin
22
This fastify plugin recognizes http requests and either redirects to an https URL or disallows the request. Useful to ensure connections utilize secure HTTP connection URLs. The logic is very similar to the [express-ssl](https://github.com/jclem/express-ssl) plugin.
33

44
This plugin can examine the request headers to determine if a request has been forwarded from a TLS-terminating proxy, a common deployment model. It relies on fastify’s [trustProxy](https://www.fastify.io/docs/latest/Reference/Server/#trustproxy) setting to learn the protocol and host name of a request sent through a proxy, such as an API gateway or load balancer.
55

6+
### Install
7+
8+
```shell
9+
npm install fastify-https-always
10+
```
11+
12+
### Usage
13+
To use the plugin, simply register it with the fastify instance. Be sure to consider the `trustProxy` setting for fastify. If your app will be deployed behind a proxy such as Heroku or an API gateway, then set trustProxy to true.
14+
15+
```js
16+
const fastify = require('fastify')({
17+
trustProxy: true
18+
})
19+
20+
fastify.register(require('fastify-https-always'))
21+
```
22+
623
### Configuration
724

825
This plugin has several optional configurations that can be used to change the behavior of the plugin. The following table lists these options for your configuration.
@@ -14,3 +31,21 @@ This plugin has several optional configurations that can be used to change the b
1431
| `redirect` | `true` | `http` requests will be redirected to the appropriate `https` service. If this config is false, then a `403 Forbidden` error is returned instead. |
1532
| `httpsPort` | `undefined` (spec uses 443 as the default https port) | Use this value to change the https port used in the redirect Location header. |
1633

34+
### Typescript Support
35+
36+
Fastify-https-always is written in Typescript and includes type declarations for the options.
37+
38+
```typescript
39+
import Fastify from "fastify"
40+
import httpsAlwaysPlugin, {HttpsAlwaysOptions} from "fastify-https-always"
41+
42+
const fastify = Fastify({trustProxy: true})
43+
// leave out options whose default is suitable
44+
const httpsAlwaysOpts: HttpsAlwaysOptions = {
45+
productionOnly: false,
46+
redirect: false,
47+
httpsPort: 8443
48+
}
49+
50+
fastify.register(allowPlugin, httpsAlwaysOpts)
51+
```

0 commit comments

Comments
 (0)