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

Close server and db connect after tests

I have koa server with mongo connection and use supertest to mock server and send requests, jest as test framework. const app = new Koa() ... export default app.listen(PORT, (err) => { if (err) console.log(err) if (!IS_TEST) { …
Khotey Vitaliy
  • 509
  • 1
  • 6
  • 18
7
votes
3 answers

Trigger a download in Koa request handler

I'm trying to trigger a download from a POST request handler in Koa with koa-router. Essentially, I'm trying to do something like this: app.js const Koa = require('koa') const router = require('./router') const app = new…
Saad
  • 49,729
  • 21
  • 73
  • 112
7
votes
2 answers

REST API with koa2. Common prefix for several routers

I have two entities, users and employees. So I want CRUD for both in different endpoints, but both of them will be mounted under "api", so I can define api_v1, api_v2 and so on. The endpoints would be something like: get api/users put…
user2670996
  • 2,654
  • 6
  • 29
  • 45
7
votes
1 answer

koa.js streaming response from remote url

I want to create a koa route that acts like a proxy for another url, which delivers a file that is usually a few dozens of Megabytes. Therefore I would like not to block when making the response. I am using this.body = yield request.get(url);…
nha
  • 17,623
  • 13
  • 87
  • 133
7
votes
2 answers

What happens when promise is yielded in javascript?

Didn't find full answer .. What happens when promise is yielded? Is such construction var p = new Promise() p.resolve(value) function * (){ yield p } equivalent to function * (){ yield value } ? UPDATE How to mix different styles of async…
akaRem
  • 7,326
  • 4
  • 29
  • 43
7
votes
2 answers

koajs session - where is the session stored?

I am using this module for koajs sessions. I checked the source code but I really cannot understand it. I am trying to know where it is saving the session data, because I see no files created, and when the server is restarted the session data is…
john doe
  • 121
  • 1
  • 10
7
votes
3 answers

Koa-router route urls that don't exist

I can't believe there is no easy answer to do this. I wish to redirect let's say; www.example.com/this-url-does-not-exist to www.example.com/ There has to be a way, all the nodejs websites with koajs just can't crash? Heres my router (I'm using…
basickarl
  • 37,187
  • 64
  • 214
  • 335
7
votes
4 answers

Running code AFTER the response has been sent by Koa

To optimize the response delay, it is necessary to perform work after are response has been sent back to the client. However, the only way I can seem to get code to run after the response is sent is by using setTimeout. Is there a better way?…
Garrett
  • 11,451
  • 19
  • 85
  • 126
7
votes
5 answers

Using Callbacks With nodejs in KOA

Recently I work on a new project and this project use JavaScript callbacks in nodejs. Now we use KOA but the problem happens when we try to use ES6 Generators and callbacks. //Calback function function load(callback){ result = null; //Do…
MBehtemam
  • 7,865
  • 15
  • 66
  • 108
6
votes
0 answers

How do I fix this TypeScript issue with Koa Session using a Koa App that is generically typed?

I'm using the following interfaces to define my context & state for koa: export interface AppState extends Koa.DefaultState { //... } export interface AppContext extends Koa.DefaultContext { models: DomainModels; connection: Connection; } and…
Chance
  • 11,043
  • 8
  • 61
  • 84
6
votes
0 answers

Content Security Policy: The page’s settings blocked the loading of a resource at blob:https://... (“frame-src”)

I have an embedded Shopify application with React (Polaris) on the frontend and Node (Koa.js) on the backend. One feature of the application is to export some information as an Excel spreadsheet. To generate the file, I'm using the xlsx package and…
Feri Forgacs
  • 101
  • 1
  • 4
6
votes
2 answers

koa-passport logout() is not clearing session

I am using koa, koa-passport and koa-session to log users in which works fine but when I call ctx.logout() the user can refresh and still be logged in. It seems that ctx.session and/or the cookies are not being correctly cleared. This still fails…
Jareth
  • 431
  • 1
  • 3
  • 16
6
votes
2 answers

How to access "request payload" in Koa web-framework?

We are using navigator.sendBeacon function to send data to Koa server, in which we are using bodyparser. If we not wrapped data into form then by default this function send data as request payload. How I can able to access this data on Koa…
RockStar
  • 1,304
  • 2
  • 13
  • 35
6
votes
3 answers

How I can use mongoose and Koa.js

I have a simple Koa app. I also use mongoose, mongodb(Mlab) I connected to mongodb. And I can find only ourCat. I see array in console. But I don't know, how I can get and show result on page. And how I can use my request to db in some…
Aaron
  • 133
  • 2
  • 7
6
votes
2 answers

How to design a multi-tenant node.js application?

Currently I am facing a technological decision to be made and personally am not able to find the solution myself. I am currently in progress to develop a multiple-tenant database. The structure would be the following: There is one core database…
alogins
  • 61
  • 1
  • 4