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
4
votes
1 answer

How to specify a static folder in Koa?

index.js: (placed inside of server folder.) const serve = require('koa-static') const Koa = require('koa'); const app = new Koa(); app.use(serve(__dirname + './public')); app.listen(3000); console.log('listening on port 3000'); I want to show…
Askar
  • 5,784
  • 10
  • 53
  • 96
4
votes
2 answers

Strange ECONNRESET error I cannot figure out

I do not know, if this is related to koa, or is problem of some other npm module or something else. I am going to start from here. So to the problem. I am having REST api written in koa v1. We are running node server in the Docker image. One of the…
daniyel
  • 652
  • 10
  • 28
4
votes
3 answers

How do I test custom Koa middleware for error handling?

As part of a migration of an older app from ExpressJs to Koa JS (v1). I've written a piece of middleware to handle any errors that occur. It looks something like this: module.errors = function * (next) { try { yield next; } catch (err) { …
purpletonic
  • 1,858
  • 2
  • 18
  • 29
4
votes
1 answer

Multipart file upload issue

I have a Koa application that has a multipart/form-data file upload that has suddenly stopped working. I have spent over 8 hours now trying to isolate the issue. What I've tried/verified: Not a Node 6 issue; same problem occurs with Node 4 (which…
Ethan Brown
  • 26,892
  • 4
  • 80
  • 92
4
votes
1 answer

Koa cookie returning `undefined`

After a POST request is sent from the browser to the /generate url in the server, I want to create a string and save it as a cookie. When a GET request is later sent from the browser to the /retrieve url in the server, I want to send that string as…
Saad
  • 49,729
  • 21
  • 73
  • 112
4
votes
2 answers

Disable Request TImeout in Koa

I am getting a connection reset error. I am fairly certain this is coming from a long running REST request, that is timing out. { [Error: socket hang up] code: 'ECONNRESET' } Is there a way to disable request timeouts in Koa, so that I can test…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
4
votes
0 answers

How to integrate swagger with koa and joi?

I am writing node API based on KOA framework. For validation I prefer Joi validation and add a middleware. Now I want integrate Swagger. But I think that I write the same part of code twice (request data validation part, one in joi validation ,…
4
votes
2 answers

How to use Browser history in react router with koa

In the express, we can just use following codes to deal with the request. The server side will send index.html when the request that isn't handled by router. app.get('*', function (request, response){ response.sendFile(path.resolve(__dirname,…
Mia
  • 107
  • 6
4
votes
1 answer

How to render the main layout and partials with koa-views + handlebars?

This is my views folder structure: - views - layouts layout.hbs - partials part.hbs home.hbs I'm rendering the template width: app.use(views(__dirname + '/views', { extension: 'hbs', map: { hbs: 'handlebars'…
Lanti
  • 2,299
  • 2
  • 36
  • 69
4
votes
1 answer

Use Koa.js with ES6

I am writing a REST API with Express for a while now. I have been reading into Koa.js and it sounds very interesting, but I can't seem to figure out how to write proper ES6 features with Koa.js. I am trying to make a structured application and this…
DevNebulae
  • 4,566
  • 3
  • 16
  • 27
4
votes
1 answer

How to get correct Auth0 bearer token?

I want to get the Auth0 bearer token for my node.js app. I got the bearer token by doing this: curl https://myproject.eu.auth0.com/oauth/token --data "client_id=ID&client_secret=SECRET&type=web_server&grant_type=client_credentials" Which returned…
MoeSattler
  • 6,684
  • 6
  • 24
  • 44
4
votes
1 answer

How can I use ES2016 (ES7) async/await in my acceptance tests for a Koa.js app?

I am in the process of writing my first Koa.js app, and having recently been introduced to the ES2016 (aka ES7) features of async / await, I wanted to make use of these. I found that my Google skills were not up to the task, and the few snippets of…
egeland
  • 1,244
  • 1
  • 12
  • 19
4
votes
2 answers

using koa and passport for authenication

I'm using koa and passport trying to implement middleware to prevent access to URIs when not authenticated. var koa = require('koa'); var session = require('koa-generic-session'); var bodyParser = require('koa-bodyparser'); var koaRouter =…
mfc
  • 3,018
  • 5
  • 31
  • 43
4
votes
1 answer

how to use koa router to define a default

I'm using koa-router to define routing paths var app = require('koa')(); var router = require('koa-router')(); app.use(router.get('/apples', function *(next) { })); app.use(router.get('/oranges', function *(next)…
mfc
  • 3,018
  • 5
  • 31
  • 43
4
votes
3 answers

Keep session in koa on multiple servers

I have multiple koa servers with a load balancer, using passport login. I would like to keep the session across all servers. My first attempt was to set the session storage to be in mysql database, but this caused the server to call mysql on each…
Avi Tshuva
  • 246
  • 2
  • 12