Commit 48ca6fe0 authored by Evan Hahn's avatar Evan Hahn
Browse files

Initial commit

parents
Pipeline #288030603 passed with stages
in 1 minute and 50 seconds
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {}
}
/node_modules/
image: node:10
stages:
- installation
- test
npm-install:
stage: installation
script:
- npm ci
cache:
paths:
- node_modules/
artifacts:
expire_in: 7 days
when: on_success
paths:
- node_modules/
npm-test:
stage: test
dependencies:
- npm-install
script:
- npm test
# Changelog
## Unreleased
This is the first version of the middleware.
The MIT License
Copyright (c) 2021 Evan Hahn
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# FLoC Block
FLoC Block is Express middleware to block Google's FLoC tracking. Help [clean up the web](https://cleanuptheweb.org/).
## Quick start
First, install the package with `npm install floc-block`. Then, in an Express app:
```js
const flocBlock = require("floc-block");
// ...
app.use(flocBlock());
```
## How it works
This middleware sets the `Permissions-Policy` response header to `interest-cohort=()`, and that's it. The middleware takes no arguments.
If the header was already set earlier in your stack, it will be overwritten.
For finer-grained control over the `Permissions-Policy` header, set the header yourself or use the [permissions-policy npm package](https://github.com/pedro-gbf/permissions-policy).
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "http";
declare function flocBlock(): (
req: IncomingMessage,
res: ServerResponse,
next: () => unknown
) => void;
export = flocBlock;
module.exports = function flocBlock() {
return function flocBlockMiddleware(_req, res, next) {
res.setHeader("Permissions-Policy", "interest-cohort=()");
next();
};
};
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "floc-block",
"author": "Evan Hahn <me@evanhahn.com> (https://evanhahn.com)",
"description": "Express middleware to block Google's FLoC tracking",
"version": "0.0.0",
"keywords": [
"express",
"floc"
],
"bugs": {
"url": "https://gitlab.com/EvanHahn/floc-block/-/issues",
"email": "me@evanhahn.com"
},
"repository": {
"type": "git",
"url": "https://gitlab.com/EvanHahn/floc-block.git"
},
"engines": {
"node": ">=10.0.0"
},
"license": "MIT",
"main": "floc-block.js",
"typings": "floc-block.d.ts",
"files": [
"CHANGELOG.md",
"floc-block.d.ts",
"floc-block.js",
"LICENSE",
"README.md"
],
"scripts": {
"pretest": "npm run lint",
"lint": "npm run lint:eslint && npm run lint:prettier",
"lint:eslint": "eslint \"**/*.js\"",
"lint:prettier": "prettier --check \"**/*.{js,ts,json,md}\"",
"format": "prettier --write \"**/*.{js,ts,json,md}\"",
"test": "ava"
},
"devDependencies": {
"ava": "^3.15.0",
"connect": "^3.7.0",
"eslint": "^7.24.0",
"prettier": "^2.2.1",
"supertest": "^6.1.3"
}
}
const test = require("ava");
const connect = require("connect");
const supertest = require("supertest");
const flocBlock = require("./floc-block");
test("setting of the header", async (t) => {
t.plan(0);
const app = connect();
app.use(flocBlock());
app.use((req, res) => {
res.end("Hello world!");
});
await supertest(app)
.get("/")
.expect("Permissions-Policy", "interest-cohort=()")
.expect("Hello world!");
});
test("overriding an existing Permissions-Policy header", async (t) => {
t.plan(0);
const app = connect();
app.use((req, res, next) => {
res.setHeader("Permissions-Policy", "to be overridden");
next();
});
app.use(flocBlock());
app.use((req, res) => {
res.end();
});
await supertest(app)
.get("/")
.expect("Permissions-Policy", "interest-cohort=()");
});
test("names its function and middleware", (t) => {
t.is(flocBlock.name, "flocBlock");
t.is(flocBlock().name, "flocBlockMiddleware");
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment