Questions tagged [koa-router]

Router middleware for koa.

Router middleware for koa.

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

139 questions
1
vote
1 answer

How can I handle GET data in koa

I am newbie in koa, and I am using koa-router. For me, the code is like: this.router.get('/user/test',function(){ debugger; }) then I visit localhost:3000/user/test?p=1&q=2, I just find that there seems no method for me to get…
CoolGuy
  • 357
  • 2
  • 16
1
vote
1 answer

koa-route Unable to run

Why below code output as 'one', not 'one' 'two'? but using express-route is ok app.use(route.get('/admin',requiredUser,index)); function *requiredUser(next){ console.log("one"); //required session yield next; } function…
1
vote
1 answer

Handling invalid requests with koa-router and koa-mount

My app uses koa-router, and it mounts the router using koa-mount, as in: var Router = require('koa-router'); var mount = require('koa-mount'); app = koa(); var router = new Router(); router.get('/foo', function *() { this.body = { success: true…
user663031
1
vote
1 answer

POST with koa (nodejs)

I keep annoyingly on finding examples that only parse JSON sent. I am trying to find an example where a POST comes from a form.
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
0 answers

Apollo Server 4: How to Mount Koa's Integration at the URL Path `/graphql`

I'm migrating from Apollo Server 3 to Apollo Server 4 and using Koa.js as my framework and @as-integrations/koa middleware. I've encountered an issue where I can't configure my Koa integration to listen to the path /graphql correctly. In Apollo…
Ondiek Elijah
  • 547
  • 8
  • 15
0
votes
0 answers

Augment Koa.Context automatically for routes with a certain middleware

I have a web app that I've written using TypeScript and Koa. All requests from the frontend to the backend pass an optional JWT via HTTP headers if, and only if, the user of the web app is signed in. On the backend I have a middleware that looks for…
Nisse
  • 1
0
votes
0 answers

Koa route called twice, first time with a purpose=prefetch header

We have a shortener Koa app that handles urls like https://my-shortener.com/ (or when developing: http://localhost:2009/aaa), and then redirects the user. I made a simple Koa app to reproduce the behaviour: index.js const port =…
devboell
  • 1,180
  • 2
  • 16
  • 34
0
votes
2 answers

How does the `use` method on Router instance of @koa/router work?

I have a very simple routing code using @koa/router: import Koa from 'koa'; import Router from '@koa/router'; const app = new Koa(); const router = new Router(); router.use('/api', (ctx, next) => { ctx.body = 'catch all with use'; ctx.status…
Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
0
votes
1 answer

How to use express-validator with koa framework?

I have built a simple koa app. Would like to use express-validator to validate the incoming API requests for post call. But Getting a failure message when starting the application: TypeError: controller.validatee is not a function\n at routes …
KGT
  • 29
  • 3
0
votes
1 answer

How to resolve KOA- next() is not a function error?

I have built a simple koa framework application.After adding routes am trying to hit the /health GET route. It throws the below error: TypeError: next is not a function at cookieParser…
KGT
  • 29
  • 3
0
votes
2 answers

Showing the result of an axios request in the browser with Koa

I’m using KOA instead of express How can I show an axios result data to the browser Here is my code: const Koa = require('Koa'); const KoaRouter = require('koa-router'); var axios = require('axios'); const app = new Koa(); const router = new…
Rafael
  • 2,413
  • 4
  • 32
  • 54
0
votes
1 answer

Overlapping routes are not working in Koa.js

When I call /my/abc/create, I always get status 400 because of the first entrypoint. How can I call second endpoint? I prefer not to change the entrypoint order. var Router = require('koa-router'); var router =…
Pytan
  • 1,138
  • 11
  • 28
0
votes
2 answers

In Koa.js [ObjectObject] while console.log("ctx : "+ ctx.request.body); but if console.log("ctx : ", ctx.request.body); like this it prints JSON

I am trying to console.log("ctx : "+ ctx.request.body); To view what is in the JSON that received when tried it shows ctx : [object Object]. But if I console.log("ctx : ", ctx.request.body); like this it prints the JSON correctly without + in…
0
votes
1 answer

koa-router has no functions

I tried to import the koa-router into my nodejs app like this: but when checking the code completion, there is no get method to be found. Or any other method. I installed it using npm install koa-router but apparently something is not working. Can…
IonicMan
  • 743
  • 1
  • 12
  • 31
0
votes
0 answers

why can't I use async and await in the second middleware?

I found a demo in the koa-router official docs. router.get( '/users/:id', (ctx, next) => { //something }, async ctx => { //I can't use await here } ); But why can't I use async and await in the second middleware? I always got Not…