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
Options
- Options for the
masqr
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 |
masqrUrl | string | The 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!');
});
Table of Contents