@24hr/redirect-matcher

1.0.6 • Public • Published

WP redirect options

Wordpress plugin

The Wordpress plugin can be downloaded here. It will just create a new options page with some ACF fields and add new API endpoint. It will also register the options to our synk plugin.

Wordpress API endpoint: /json/api/general/redirects

NPM module

There is a NPM module that includes a helper function to match urls. This helper supports wildcard paths.

By passing the redirect options from Wordpress along with the request path it will return useful data. If no match it will return null.

Returned object (if match) contains the URL to redirect to, code to set as status code and headers that are recommended to use.

Koa example:

const { redirectMatcher } = require('@24hr/redirect-matcher');
app.use(async (ctx, next) => {
    const redirectOptions = await getRedirectOptionsSomehow(); // <-- This part is your responsibility

    const redirectData = redirectMatcher(redirectOptions, ctx.path);

    if (redirectData) {
        ctx.status = redirectData.code;
        ctx.set(redirectData.headers);
        ctx.redirect(redirectData.url);
    } else {
        await next();
    }
});

Readme

Keywords

none

Package Sidebar

Install

npm i @24hr/redirect-matcher

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

12.8 kB

Total Files

6

Last publish

Collaborators

  • inna.aleshina
  • simon.sporrong
  • mikaela.ruden
  • jaarni
  • daniumdev
  • thjo
  • richardsweeney
  • alexander-nilsson
  • camilo.tapia
  • 24hr-machine-user
  • insidenpm
  • bextex
  • victorglimskog
  • resurs-wikskold
  • younous_abdallah
  • resurs_software_solutions_machine_user