Coder Social home page Coder Social logo

ladjs / koa-redirect-loop Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 1.05 MB

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

Home Page: https://lad.js.org

License: MIT License

JavaScript 98.89% Shell 1.11%
koa http redirect loop prevent endless 302 301 referrer referer

koa-redirect-loop's Introduction

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

koa-redirect-loop's People

Contributors

niftylettuce avatar shadowgate15 avatar titanism avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

shadowgate15

koa-redirect-loop's Issues

Core bug

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:485:11)
    at Cookies.set (/Users/foo/Projects/forwardemail.net/node_modules/cookies/index.js:116:13)
    at Object.set (/Users/jack/Projects/forwardemail.net/node_modules/koa-generic-session/lib/session.js:462:20)
    at /Users/foo/Projects/forwardemail.net/node_modules/koa-generic-session/lib/session.js:189:28
    at Generator.next (<anonymous>)
    at step (/Users/foo/Projects/forwardemail.net/node_modules/koa-generic-session/lib/session.js:3:191)
    at /Users/foo/Projects/forwardemail.net/node_modules/koa-generic-session/lib/session.js:3:361

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.