Questions tagged [koa-router]

Router middleware for koa.

Router middleware for koa.

https://github.com/alexmingoia/koa-router

139 questions
1
vote
0 answers

Why is my koa application timing out when testing a route with Jest/Supertest

Summary of Problem Receiving : Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout when trying to run a test with Jest and supertest. Specs Koa2 project, Jest/Supertest testing, Babel 7.9.0…
Michael Jay
  • 503
  • 3
  • 15
1
vote
1 answer

Cannot set Koajs' ctx.status and ctx.body when using request-promise

I'm currently coding the manual setup of authenticating a Shopify app, similar to how they set it up in NodeJS and Express. For the application, I'm using NodeJS and the Koa framework. I'm also using @koa/router for routing and attempting to use…
Joseph Woolf
  • 500
  • 5
  • 14
1
vote
2 answers

How to create post request with Koa nodejs

I have just started with the Koa and made a basic setup with the following code const Koa = require('koa'); const app = new Koa(); // logger var port = process.env.PORT || 8080; // set our port // response app.use(async ctx => { …
Profer
  • 553
  • 8
  • 40
  • 81
1
vote
0 answers

A Cleaner way, how to refactor async call

I have the following endpoint @Patch("/games/:id") @HttpCode(200) async updateGame(@Param("id") id: number, @Body() update: Partial) { const updatedGame = await Game.findOne(id); if (!updatedGame){ throw new…
newDev
  • 97
  • 1
  • 13
1
vote
0 answers

Return `Not Found` in koa-router

In app.js, I have some code like following const Router = require('koa-router') let enpackage = new Router() enpackage.get('/en', async ( ctx )=>{ ctx.redirect('/') }) let router = new Router() router.use('/en', enpackage.routes(),…
yupang
  • 155
  • 1
  • 2
  • 16
1
vote
2 answers

MarkoJS for loop over array of objects

I really need help with a pretty simple and trivial problem, but here it goes. I am using marko on the server side in NodeJS and am rendering my views via: ctx.render({ }); with koa-router and koa. I need help in the html dept on how to go about…
1
vote
1 answer

POST request with parameters doesn't work with koa-router

I'm trying to build a simple REST API with Koa. For this, I am using koa-router. I have two problems: Whenever I try to add parameters to my POST-Method in mainRouter.ts like ":id", Postman shows a "not found". My request:…
Fuchur Kool
  • 53
  • 2
  • 7
1
vote
0 answers

ctx.render doesn't redirect the page

I'm pretty sure It's because ctx.render function is just for rendering page, but I have no idea what to do to do what I'm tryna do. Basically, I'm trying to redirect user to user's mypage after login, with jwt token in the header so I used axios to…
Phillip YS
  • 784
  • 3
  • 10
  • 33
1
vote
2 answers

koa2+koa-router+mysql keep returning 'Not Found'

Background I am using koa2 with some middlewares to build a basic api framework. But when I use "ctx.body" to send response in my router, the client side always receive "Not Found" My code ./app.js const Koa = require('koa'); const app = new…
J.Lyu
  • 932
  • 7
  • 16
1
vote
0 answers

Koa js JOI validator is not working for post method

I'm using koa-joi-validator in KOA js. JOI validation works properly for GET method. But when POST method triggers it just receives the request and that's it, No validation triggered, No response sent. GET <-- GET /user/1 --> GET /user/1 200 107ms…
sravis
  • 3,562
  • 6
  • 36
  • 73
1
vote
1 answer

How to get rid of a "phantom" route that koa-router adds without being defined

I'm starting devel on very small app, and decided to use koa Framework with koa-router ( among some other middleware in the future) Question is that after specifying my routes, a strange catch-all, no method, no url route appears // excerpt of…
mtsdev
  • 613
  • 5
  • 11
1
vote
2 answers

Koa 2 + Passport + async

Trying to implement a local Passport strategy in Koa 2 but I'm missing something vital... When my route hits passport.authenticate(), I'm able to retrieve my user but I'm never returning from that await(), so my code doesn't progress any…
Nico Galluzzo
  • 485
  • 1
  • 3
  • 8
1
vote
1 answer

How to set body inside a Promise?

In code bellow, I would like that somehow changed commented part should be able to set document's body instead of "this.body = 'test';" (it still should be Promise solution). 'use strict' var app = require('koa')(), router =…
olegzhermal
  • 799
  • 10
  • 26
1
vote
1 answer

How to manage URL with or without ? and /

In my Koa app, I've this kind of router : app .use(router(app)) .all('/', frontRoutes.home.index); My problem is that : mydomain.com mydomain.com/ mydomain.com? Are routed by the same route. It could be great but for Google it's not. Says…
MathKimRobin
  • 1,268
  • 3
  • 21
  • 52
1
vote
1 answer

Content-type header is always the same while testing koa routes with supertest

I have an application build with koa and koa-router. When testing routes with supertest I face a problem, that content-type response header is always application/json; charset=utf-8. const app = koa(); router .get('/img', function *(next) { …
Alexandr Lazarev
  • 12,554
  • 4
  • 38
  • 47