Skip to content

Prevent redirect loops with sessions since HTTP referrer header is unreliable and ensures sessions are saved upon redirect

License

Notifications You must be signed in to change notification settings

ladjs/koa-redirect-loop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Nov 21, 2022
38ff7f1 · Nov 21, 2022

History

40 Commits
Jul 1, 2022
Jul 1, 2022
Nov 21, 2022
Jun 3, 2022
Dec 23, 2019
Jul 1, 2022
Jul 1, 2022
Jul 1, 2022
Jun 3, 2022
Jul 1, 2022
Jun 3, 2022
Dec 23, 2019
Jun 3, 2022
Jun 3, 2022
Jun 3, 2022
Dec 23, 2019
Jul 2, 2022
Jul 21, 2022
Nov 21, 2022

Repository files navigation

koa-redirect-loop

build status code style styled with prettier made with lass license npm downloads

Prevent redirect loops with sessions since HTTP referrer header is unreliable and ensures sessions are saved upon redirect

Note that this package only supports koa-generic-session, since other packages do not expose a save method used in res.end override.

Table of Contents

Install

npm:

npm install koa-redirect-loop

Usage

const Koa = require('koa');
const session = require('koa-generic-session');
const RedirectLoop = require('koa-redirect-loop');

const redirectLoop = new RedirectLoop({
  defaultPath: '/',
  maxRedirects: 5,
  logger: console
});

const app = new Koa();
app.keys = [ 'secret' ];

app.use(session());
app.use(redirectLoop.middleware);

Options

  • getDefaultPath (Function) - function which accepts ctx argument and returns a path to fallback to, defaults to either /${ctx.request.locale} (e.g. if using @ladjs/i18n) or /
  • defaultPath (String) - path to fallback to, defaults to '/'
  • maxRedirects (Number) - maximum number of redirects to allow, defaults to 5
  • console (Object) - a logger instance, defaults to console

Contributors

Name Website
Nick Baugh http://niftylettuce.com/

License

MIT © Nick Baugh