npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-recaptcha-rest

v0.1.0

Published

Protect public routes from spam through recaptcha

Downloads

5

Readme

express-recaptcha-rest

Protect public routes from spam through recaptcha

About

The motivation behind this module was to protect an api endpoint, for user signups from spam. Therefore this module does not deal with the client side of recaptcha at all.

Getting Started

Install the module with npm

npm install -save express-recaptcha-rest

Once installed require it and add it as middleware to a route.

const express = require('express')
const recaptcha = require('express-recaptcha-rest')

const app = express()

app.post('/some/route', recaptcha({ secret: 'your_secret' }), routeHandler)

Options

  • field

    • The name of the filed to look for the recaptcha response in the request
    • Per default it is set to 'g-recaptcha-response'
    • The middleware looks for the response in the following order: headers, query, body
  • secret

    • The secret to use in the verification request
    • If set to 'test_secret' a fixed secret is used which will always make the verification request succeed. Here are some more infos.

Behaviour

Invalid recaptcha response

If the recaptcha response supplied by the client is invalid the middleware ends the response with a 422 status. Middleware and handlers which are further down the line won't get executed.

No recaptcha response

If the client does not send any recaptcha response at all or not under the in options specified key the response will end with a 400 status.

Successful verification

The middleware adds a req.recaptcha property to the request. This property holds the response from the verification request.

Skip verification

If the middleware finds req.recaptcha set to false, by an early middleware, verification will be skipped.

errors

The following errors will be passed to next as the only argument.

verification request failed

This error indicates that the verification request could not be sent.

verification request returned status %d

Should the response to the verification request have any other status than 200 this error is given.

parsing body of verification response failed

If the JSON in the body of the response can not be parsed you will see this error.

bad verification request

This error shows that the request it self was invalid, most likely an invalid recaptcha secret.