Express
This guide will show you how to use Corlink with Express. And provide minimal examples of using Corlink with Express.
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-express
package and express
and cookie-parser
if you haven't already installed them in your project
NPM
npm install @rubynetwork/corlink-express express cookie-parser
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 |
Examples
- Minimal example of using Corlink with Express (both CommonJS and ES Modules).
const express = require('express');
const cookieParser = require('cookie-parser');
const { corlinkExpress } = require('@rubynetwork/corlink-express');
const cookieSecret = 'your-secret';
const app = express();
// Use cookie-parser middleware (MUST have signed cookies)
app.use(cookieParser(cookieSecret));
app.use(corlinkExpress({
deniedFilePath: 'denied.html',
unlockedPaths: ['/bare/'],
whiteListedURLs: ['https://maindomain.com', 'https://subdomain.maindomain.com'],
corlinkUrl: 'https://corlink.example.com',
corlinkAPIKey: 'your-api-key',
}));
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});
Table of Contents