Questions tagged [koa]

Koa is a web framework which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Koa is a web framework for Node.js, designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Use this tag if your question is about the application middleware generators and its cascading properties or the use of App.Settings. Note also the existence of the tag if you're using the middleware API with async/await.

Resources

1232 questions
0
votes
2 answers

Automatically logging in a user with KoaJS and PassportJS

I'm trying to automatically log in a user with PassportJS. This is my current code: myRouter.get('/signin', function* (next) { user = {...}; var res = this.res; // needed for the function below this.req.login(user, function(err) { …
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
1 answer

Sign in user automatically via passport-local

I am using passport-local project which is working great. I have however implemented a email verification system now. this works and currently it redirects the user when verified to the sign in page to sign in. I would however like my system to…
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
1 answer

KoaJS middleware and database access

If I had this to show an index for a users model: app.use(route.get('/user', list)); function *list() { var res = yield users.find({}); this.body = res; }; Is it possible to put the database access part into its own middleware and then call…
Dolbery
  • 185
  • 1
  • 12
0
votes
3 answers

Generators in KOA

How does work app.use in KOA? When I set some generator inside app.use, everything works perfect. How can I do the same elsewhere? When I just execute generator manual: var getRelationsList = function *() { var res = yield db.relations.find({}); …
OKey
  • 182
  • 1
  • 2
  • 10
0
votes
1 answer

NPM install not working on OpenShift (via rhc ssh) (permissions)

Get into remote ssh via: rhc ssh Need to intall a module: npm install koa --save Gives the result: npm http GET https://registry.npmjs.org/koa npm http 304 https://registry.npmjs.org/koa npm WARN engine koa@0.19.1: wanted: {"node":">=…
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
2 answers

Subdomain routing with Koa?

I wish to be able to do the following: mydomain.com/this/that Should redirect differently to: a.sub.domain.mydomain.com/this/that I see Express has the following: github.com/bmullan91/express-subdomain Koa does have…
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
1 answer

Koa - Best practice for yield error handling

I'm getting my hands dirty in Koa.js and am looking for a best practice on returned error handling for generators, if there is one. Take the following: var sql = require('./lib/sql'); app.use(function *(){ var results = yield sql.query('select…
dthree
  • 19,847
  • 14
  • 77
  • 106
0
votes
1 answer

How to refresh resources in Node without restarting the server?

I'm using koa-static-folder, but apparently it doesn't provide access to files added after the server starts without the need to restart the actual server. Are there any middleware or libraries that do?
0
votes
1 answer

File not uploading via post to kojs

A file is not being downloaded to the server from a html post. Here is the koa server code project/app.js: 'use strict'; /** * Module dependencies. */ var logger = require('koa-logger'); var serve = require('koa-static'); var parse =…
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
0 answers

"Generator already running" message on any error

I have a very simple generator function, like this exports.whatever = function *(next) { this.body = 'wow'; z }; Now, there obviously is a syntax error here ('z' on the third line), but with koa's generators, the error I get in the console is…
john doe
  • 121
  • 1
  • 10
0
votes
1 answer

Cannot yield next inside anonymous function

I have a generator function, like this: function *(next) { this.redis.get('foo', function(e, r){ console.log(r) yield next; }) } I was thinking I could use a co style coding, by using var r = yield this.redis.get('foo') but apparently…
john doe
  • 121
  • 1
  • 10
0
votes
2 answers

Send start of page's HTML to the server whilst waiting for database

If I take out my database access code my webpages are dealt with in a few ms. When the database access code is added then the requests go up to 400ms+. Is it possible to send the top of the page to the browser whilst waiting on the database to…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
0
votes
2 answers

How do I access the logged in user object in a view?

Once a user has been logged in, how do I reference this.req.user from inside of a view? I think this would involve updating the locals collection of the Jade middleware. I haven't been able to get a reference to this object though. Up until now I've…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
0
votes
0 answers

Refreshing site in react.js not working with query parameters

I have problem when I hit F5 in the browser. I have route defined in react-router: and route on node.js…
Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33
0
votes
2 answers

ES6 Koa.js run generator function to completion and return asynchronously

Using koa.js, I want to make an API which runs a generator function that runs a long time in the background, but sends a token back to the user immediately. The user can then use that token to retrieve status of their job later. 'use strict'; var…
Willy Zhang
  • 473
  • 4
  • 12