Express (Masqr)

This guide will show you how to use Corlink (using Masqr compat) with Express. And provide minimal examples of using Corlink with Express.

Prerequisites

  • Node.js v18 or later
  • A Masqr server.
  • 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 masqr 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
masqrUrlstringThe URL of the Masqr server.Yes

Examples

  • Minimal example of using Corlink (Masqr compat) with Express (both CommonJS and ES Modules).
const express = require('express');
const cookieParser = require('cookie-parser');
const { masqr } = 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(masqr({ 
    deniedFilePath: 'denied.html',
    v3: false, //Set to true if you want to use multiple html files (based off of the hostname)
    unlockedPaths: ['/bare/'],
    whiteListedURLs: ['https://maindomain.com', 'https://subdomain.maindomain.com'],
    masqrUrl: 'https://corlink.example.com/validate?license=',
}));

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 { masqr } 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(masqr({ 
    deniedFilePath: 'denied.html',
    unlockedPaths: ['/bare/'],
    whiteListedURLs: ['https://maindomain.com', 'https://subdomain.maindomain.com'],
    masqrUrl: 'https://corlink.example.com/validate?license=',
}));

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(3000, () => {
    console.log('Example app listening on port 3000!');
});