Giter Site home page Giter Site logo

convert's People

Contributors

3imed-jaberi avatar 75lb avatar gyson avatar niftylettuce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

convert's Issues

convert.back() not respecting return from function?

I am working on a Koa v1 app and would like to implement new routes with async/await instead of generator functions. I found this library has convert.back() which is mostly working for me. However, the following example code will illustrate my problem:

router.get('/endpoint',
async function(next) {
    const token = this.request.headers.token;
    if (!token) {
        this.response.status = 401;
        return;
    }
    // I assume next is a Promise so this is not an issue?
    await next;
},
async function(next) {
    // This code still executes, even if there is no token defined on the headers.

    // Do something important that shouldn't execute with invalid auth...
});

return convert.back(router.routes());

If there is no token defined, the endpoint does return a 401 and exits the first function, but the second function is still executed. If I set up the first function as a generator function and use yield next, it works as would be expected.

Versions:

node: 6.13.1
npm: 3.10.10

├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
├─┬ [email protected]
│ ├── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]

Any special steps if using koa-mount?

I'm planning on upgrading to koa 2.x, however the notes seems to indicate that koa-router needs to be update first. I'm wondering if there is something special about koa-mount as well?

Does not work with node v6.5

Hi,
I have a webapp that I built using the koa v2 framework. I use koa-convert, koa-generic-session and koa-redis to store user sessions in my redis instance. Since upgrading to node v6.5, my webapp fails with the following stacktrace:

TypeError: Cannot read property 'done' of undefined
      at next (/Users/dev/work/node_modules/co/index.js:98:14)
      at onFulfilled (/Users/dev/work/node_modules/co/index.js:69:7)
      at /Users/Stephen/dev/work/node_modules/co/index.js:54:5
      at Object.co (/Users/dev/work/node_modules/co/index.js:50:10)
      at next (/Users/dev/work/node_modules/co/index.js:99:29)
      at onFulfilled (/Users/dev/work/node_modules/co/index.js:69:7)

It worked fine with node v6.4. The stacktrace doesnt go past co, but through trial and error, I deleted a lot of third party libs and middleware and narrowed it down to this block of code:

app.use(convert(session({
  key: 'session',
  errorHandler(err, type, ctx) {
    console.error(err, type)
  },
  store: redisStore({ url: config.redis.url })
})))

which can be reduced to app.use(convert(session())) and still trigger the same bug.

I do not use the convert lib anywhere else in the app so I cannot quickly test to see if the issue is specifically in the convert or session lib.

throws error if `next` not defined

I'd like to be able to call converted middleware without a next param, similar to what happens in compose (https://github.com/koajs/compose/blob/master/index.js#L20). For example, using koa 2.x params middleware:

async function noop () {}
export async function organizationIdParam (id, ctx, next) {
  await convert(rbac.allow('read:organization', { organization: id }))(ctx, noop);
  ctx.organization = await Organization.findById(id);
  await next();
}

It would be nice to instead be able to call it like this:

export async function organizationIdParam (id, ctx, next) {
  await convert(rbac.allow('read:organization', { organization: id }))(ctx);
  ctx.organization = await Organization.findById(id);
  await next();
}

What do you think?

move to koajs organization

i've invited you to be part of the @koajs/koa-v2 team in @koajs. i'd like you to transfer your repo over. i'm not sure how transferring works when you're not an owner of the organization, though. let me know if you run into any issues.

convert bug

koa.use(convert(hbs.middleware({
    extname: '.html',
    viewPath: ['./www/admin', './www/home'],
    layoutsPath: './www',
    partialsPath: ['./www/admin', './www/home'],
    disableCache: true
})));

koa.use(async(ctx, next) => {
    const render = ctx.render;
    ctx.render = async function _convertedRender() {
        return co.call(ctx, render.apply(ctx, arguments))
    }

    await next();
});

await ctx.render('index_index');

###Question###
If I open the cache, view rendering not to come out, when I closed the cache, the view can render.

###I recorded a GIF###
http://www.wemallshop.com/hbs.gif

###Result###
497d7471-fbc4-48db-9527-1f7cfba7b8af

Actually return data, but this. The body has no output to the browser

Passing argument not working?

First off, I do not know if this belongs here in this module, but I'll start here. I'm experimenting with the following code:

var convert = require('koa-convert');
var genbind = require('generator-bind');

function* myGen(i) {
    console.log(this.x, i);
}
myGen = genbind({x:666}, myGen);
convert(myGen)(9); // <--- this outputs 666 undefined, was expecting 666 9

I can't seem to pass an argument to the generator function. If this isn't to do with koa-convert then I'm guessing generator-bind is at fault.

Passing arguments v1.x into middleware?

Currently I can't figure out an elegant way for passing arguments into v1.x middleware.

Is this something that could be useful to anyone?

I'm using the koa-ratelimiter library which currently doesn't have v2.x support. However I'd like to also pass in arguments.

The old version looked like this

app.use(ratelimit({
  max: opts.ratelimit,
  duration: opts.duration,
  db: redis.createClient()
}));

What I'd like to do is pass in the options as a second parameter to convert.

app.use(convert(ratelimit, {
  max: opts.ratelimit,
  duration: opts.duration,
  db: redis.createClient()
}));

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.