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

How to access koa context in another generator function?

In Koa I can accesss a Koa Context in the first generator function via this: app.use(function *(){ this; // is the Context } But if I yield to another generator function I can't access the context via this anymore. app.use(function *(){ …
Felix
  • 3,783
  • 5
  • 34
  • 53
5
votes
2 answers

Get user id socket.io, passport, koa

I'm using Koa, Passport.js and koa-session to authenticate users. So it basically looks like: // session var session = require('koa-session'); app.keys = [config.secret]; app.use(session()); // auth require(__dirname+'/lib/auth'); //…
Cohars
  • 3,822
  • 1
  • 29
  • 50
4
votes
4 answers

Postman set-cookie not working with the domain

I want to controll authentication with cookies. And In my browser working successfully. But When I tried to test with postman, Postman doesn't add cookie to new request. step - I login and response header like that: But the response cookies tab…
akasaa
  • 1,282
  • 4
  • 13
  • 33
4
votes
1 answer

this.validateBody is not validating the keys even keys are in body of request nodejs koa

yield this.validateBody({ password: 'required', email_id: 'required' }); trying to validate the request body but when everything is in it, it still says Fields are required. everything is in it. node 12.20.0 koa-validation 0.1.9
4
votes
1 answer

Unable to link backend API routes - NextJS

I am making a shopify app and have created a Koa + NodeJS backend and NextJS running in frontend, in the same port, and also I have created a custom server.js file When running locally in my PC, its running all right, all the routes work as…
4
votes
1 answer

Redact request headers from pino logging

I'm using koa-pino-logger and by default I get that full request details when the request is completed: req: { "id": 1, "method": "POST", "url": "/v1/applications/c2cc6b32-1533-4c4c-b8b6-b581855839bb/applicants", "headers": { …
Naguib Ihab
  • 4,259
  • 7
  • 44
  • 80
4
votes
2 answers

Type 'User | undefined' is not assignable to type 'User'

User controller: import { User } from './user'; export class UserController { public static async getuser(ctx: BaseContext) { const userRepository: Repository = getManager().getRepository(User); const user: User = await…
Alexander Kim
  • 17,304
  • 23
  • 100
  • 157
4
votes
1 answer

How to fix "Choose either to return a promise or call 'done'" in Azure Functions with Koa

I'm trying to get koa working with azure functions. The "hello world" app is is already working via koa but while running the dev server azure is throwing an Error: Choose either to return a promise or call 'done'. Do not use both in your…
Kai
  • 71
  • 1
  • 6
4
votes
4 answers

How to serve the same static files regardless of the route?

I have a react App. With webpack I build for production. Now I try to set a little koa server to serve the static files generated by webpack for production. So I did this import Koa from 'koa' import serve from 'koa-static' const app = new…
doums
  • 470
  • 10
  • 24
4
votes
1 answer

Set header cache control in KOA framework

I am working with an app built with KOA framework and I'm trying to figure out why a page is cached. In all browsers even a hard reload won't work. You literally have to clear cache to see the page update. I want to add this to my index.js but I do…
Kenny Johnson
  • 452
  • 5
  • 15
4
votes
2 answers

How can I get create-react-app to use an IP to connect to my api server?

I'm using Facebook's create-react-app. When I start the web-client I see in console: You can now view web-client in the browser. Local: http://localhost:3000/ On Your Network: http://192.168.1.107:3000/ The problem is my web-client…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
4
votes
1 answer

How to TDD koa2 with mocha?

I'm trying to get a TDD workflow going with koa2/mocha/chai/chai-http but my problem is that when I run the tests the koa2 server keeps running after the tests are finished. So that I have to Ctrl+C (kill) it every time. Can anyone tell me how to…
4
votes
1 answer

Koa2: how to write chain of middleware?

So in express, we can have a chain of middleware, copies an example: middleware = function(req, res){ res.send('GET request to homepage'); }); app.get('/', middleware, function (req, res) { res.send('GET request to homepage'); }); What's the…
user3552178
  • 2,719
  • 8
  • 40
  • 67
4
votes
2 answers

koa js: What does "next" refer to, and can cascading be implemented differently?

I'm trying to wrap my head around the way koajs cascades by awaiting on "next()" before resuming request processing. As far as I can tell, "next" simply refers to the next sequential app.use() in the script. Can someone more familiar with koajs…
MFave
  • 1,044
  • 2
  • 8
  • 19
4
votes
4 answers

How to do graceful stop for koajs server?

There are a lot of examples of graceful stop for expressjs, how can I achieve the same for koajs? I would like to disconnect database connections as well I have a mongoose database connection, and 2 oracle db connection…
Sibelius Seraphini
  • 5,303
  • 9
  • 34
  • 55