Skip to content

Commit

Permalink
factor path-to-regexp out of the project.. implement regexp blacklist…
Browse files Browse the repository at this point in the history
… paths
  • Loading branch information
75lb committed Sep 11, 2024
1 parent d553481 commit b382f65
Show file tree
Hide file tree
Showing 8 changed files with 1,274 additions and 657 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [12, 14, 16, 18, 20, 22]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npm run test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-20 Lloyd Brookes <[email protected]>
Copyright (c) 2016-24 Lloyd Brookes <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![view on npm](https://img.shields.io/npm/v/lws-blacklist.svg)](https://www.npmjs.org/package/lws-blacklist)
[![npm module downloads](https://img.shields.io/npm/dt/lws-blacklist.svg)](https://www.npmjs.org/package/lws-blacklist)
[![Build Status](https://travis-ci.org/lwsjs/blacklist.svg?branch=master)](https://travis-ci.org/lwsjs/blacklist)
[![Dependency Status](https://badgen.net/david/dep/lwsjs/blacklist)](https://david-dm.org/lwsjs/blacklist)
[![view on npm](https://badgen.net/npm/v/lws-blacklist)](https://www.npmjs.org/package/lws-blacklist)
[![npm module downloads](https://badgen.net/npm/dt/lws-blacklist)](https://www.npmjs.org/package/lws-blacklist)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/lwsjs/blacklist)](https://github.com/lwsjs/blacklist/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/lwsjs/blacklist)](https://github.com/lwsjs/blacklist/network/dependents?dependent_type=PACKAGE)
[![Node.js CI](https://github.com/lwsjs/blacklist/actions/workflows/node.js.yml/badge.svg)](https://github.com/lwsjs/blacklist/actions/workflows/node.js.yml)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)

# lws-blacklist
Expand All @@ -16,4 +17,4 @@ Adds the following options to lws.

* * *

&copy; 2016-20 Lloyd Brookes \<[email protected]\>.
&copy; 2016-25 Lloyd Brookes \<[email protected]\>.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const EventEmitter = require('events')
import EventEmitter from 'events'
import arrayify from 'array-back'

class Blacklist extends EventEmitter {
description () {
Expand All @@ -16,13 +17,14 @@ class Blacklist extends EventEmitter {
}

middleware (options) {
const arrayify = require('array-back')
const blacklist = arrayify(options.blacklist)
if (blacklist.length) {
const { pathToRegexp } = require('path-to-regexp')
this.emit('verbose', 'middleware.blacklist.config', { blacklist })
return function (ctx, next) {
if (blacklist.some(expression => pathToRegexp(expression).test(ctx.path))) {
const pathIsBlacklisted = blacklist.some(function (re) {
return re.test(ctx.path)
})
if (pathIsBlacklisted) {
ctx.status = 403
} else {
return next()
Expand All @@ -32,4 +34,4 @@ class Blacklist extends EventEmitter {
}
}

module.exports = Blacklist
export default Blacklist
Loading

0 comments on commit b382f65

Please sign in to comment.