Fastify
This guide will show you how to use Corlink with Fastify. And provide minimal examples of using Corlink with Fastify.
Prerequisites
- Node.js v18 or later
- An API key from a Corlink server. - Need One? Join our Discord and open a ticket.
- A denied file. - Need help setting up a denied file? Check out our Denied File Setup guide
Installation
First, install the @rubynetwork/corlink-fastify
package and fastify
and (optionally) @fastify/cookie
if you haven't already installed them in your project
NPM
npm install @rubynetwork/corlink-fastify fastify @fastify/cookie
Options
- Options for the
corlinkExpress
middleware.
Option | Type | Description | Required |
---|---|---|---|
deniedFilePath | string | The path to the file that will be served when a request is denied. | Yes |
unlockedPaths | string | An array of paths that will not be checked by Corlink. | Yes |
whiteListedURLs | string | An array of URLs that will not be checked by Corlink. | Yes |
corlinkUrl | string | The Url of the Corlink server. | Yes |
corlinkAPIKey | string | The API key of the Corlink server. | Yes |
builtinCookieParser | boolean | Whether to use the built-in cookie parser. | No |
Examples
- Minimal example of using Corlink with Fastify (both CommonJS and ES Modules).
- The examples with (cookie parse) are using the built-in cookie parser. If you want to use your own cookie parser, you can set
builtinCookieParser
tofalse
and use your own cookie parser.
const express = require('fastify');
const corlink = require('@rubynetwork/corlink-fastify');
const app = fastify();
app.register(corlink, {
deniedFilePath: 'denied.html',
unlockedPaths: ['/bare/'],
whiteListedURLs: ['https://maindomain.com', 'https://subdomain.maindomain.com'],
corlinkUrl: 'https://corlink.example.com',
corlinkAPIKey: 'your-api-key',
//can be optionally deleted if you just want the default
builtinCookieParser: true,
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen({ port: 3000 }, () => {
console.log('Example app listening on port 3000!');
});
Table of Contents