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
Yarn
yarn add @rubynetwork/corlink-express express cookie-parser
PNPM
pnpm add @rubynetwork/corlink-express express cookie-parser

Options

  • Options for the corlinkExpress middleware.
OptionTypeDescriptionRequired
deniedFilePathstringThe path to the file that will be served when a request is denied.Yes
unlockedPathsstringAn array of paths that will not be checked by Corlink.Yes
whiteListedURLsstringAn array of URLs that will not be checked by Corlink.Yes
corlinkUrlstringThe URL of the Corlink server.Yes
corlinkAPIKeystringThe 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!');
});
import express from 'express';
import cookieParser from 'cookie-parser';
import { corlinkExpress } from '@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!');
});