Questions tagged [koa-router]

Router middleware for koa.

Router middleware for koa.

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

139 questions
0
votes
1 answer

Why does 'koa-static' middleware keeps returning 404?

I'm trying Koa by using koa-static. But it keeps returning 404 (Body: Not Found) when using multilevel inclusion relationship. I don't know the reason. To reproduce, Windows 10 x64, Node v9.11.1 Koa v2.5.1, koa-compose v4.1.0, koa-static v4.0.3,…
Fuu
  • 165
  • 2
  • 11
0
votes
0 answers

Error Handling with Koa and routing-congrollers

I am looking for a a solution of a generalised error handing when using the library routing-controllers. My custom error handling should be able to catch any rejected Promises coming from the Controller, build a response body from it and sets the…
peterschrott
  • 570
  • 5
  • 25
0
votes
1 answer

Regex with repeated group in koa-router is not working as expected

I want to call an endpoint with a comma separated list, lets say I want to call with e.g. "hey,you" or "hey,you,abc" If I call with curl "http://localhost:8896/hey,you" it is working with the following route: router.get('/:id([a-z]{3},[a-z]{3})',…
Kristoffer
  • 264
  • 2
  • 4
  • 16
0
votes
1 answer

Mongoose update doesn't work

I'm trying to add blockDate into user db, but the code below doesn't make any changes. I checked out that data.username and blockDate are valid value. I get { ok: 0, n: 0, nModified: 0 } from res variable. how can I figure out what is wrong with…
Phillip YS
  • 784
  • 3
  • 10
  • 33
0
votes
3 answers

How do I access libraries I'm adding via require, in my Node/Koa server

I'm trying to require an external library in my Node app (Koa server). I'm adding njwt in my main server.js file var njwt = require('njwt'); But I can't access njwt, in my route handler function it gives an error saying njwt is undefined. From this…
Qasim
  • 1,554
  • 1
  • 13
  • 22
0
votes
1 answer

koa-router error router.routes is not a function

When I try to use koa-route 3.2.0 example from their website, I got error message router.routes is not a function const Koa = require('koa'); const router = require('koa-route'); const app = new Koa(); app.use(logger()); router.get('/users', (ctx,…
Matt
  • 8,195
  • 31
  • 115
  • 225
0
votes
1 answer

Error: Can't set headers after they are sent using koa

Stack Overflow has a ton of questions regarding this error. Every one with its context. I have tried applying most of the solutions suggested but none is working. I am also new to koa and mongoose "use strict" const Koa = require('koa') const Router…
Sean
  • 360
  • 3
  • 17
0
votes
1 answer

koa router doesn't work, sends 404

If I send POST such /image/cover or /image/sub/ from client, the router function doesn't work at all so It sends 404. It's supposed to work but I literally have no idea. I never had this case It just doesn't work for no reason. router import Router…
Phillip YS
  • 784
  • 3
  • 10
  • 33
0
votes
1 answer

Koa-better-body file uploading not working

I'm using Koa-better-body with Koa2, and I want to handle single file uploads in a POST form submission (input type=file). While all the other fields show up properly under ctx.request.fields, i.e. ctx.request.fields.title, my file input's contents…
Qasim
  • 1,554
  • 1
  • 13
  • 22
0
votes
3 answers

Migrating koa v1 to v2

I'm using some module with koa and they only have this documentation which is written in koa v1 not v2. and since I've never used v1 before, I have no idea how to write this in v2. app .use(body({ IncomingForm: form })) .use(function * ()…
Phillip YS
  • 784
  • 3
  • 10
  • 33
0
votes
1 answer

Nodejs, koa-router, koa-views (twig) return "Not found"

So I started my new project and a friend of mine conveiced me to ditch PHP and give Nodejs a try with rethinkDB. I installed everything and without routes, it works. But once I add the routes, I got : Not Found with no error on the…
Jayd
  • 183
  • 3
  • 15
0
votes
1 answer

How to return response after database I/O finish in Koa-router?

Using Koa and Koa-router, I write a function to accept POST on /videos and then save the video into HDFS(a distributed database). After the saving process finishing, the response should be sent to client saying that the uploading is finish. However,…
guo
  • 9,674
  • 9
  • 41
  • 79
0
votes
0 answers

How can I render xml using Koa.js?

It seems like html breaks if I just render xml text using ctx.body because everything goes into body element not as raw xml. I read all the documentation but couldn't find proper response function for rendering xml. This is my code and how it looks…
Phillip YS
  • 784
  • 3
  • 10
  • 33
0
votes
1 answer

Koa.js route() is not a function

I just made simple koa app that returns rss xml by tag using parameter. and seems like middleware can't read router from router file. I have no idea why It doesn't work. I'm running this app.js with babel-node. and It keeps saying this error…
Phillip YS
  • 784
  • 3
  • 10
  • 33
0
votes
1 answer

Named Parameters not Routing in Node using Koa 2

I reviewed and followed the guides of: https://github.com/koajs/koa https://github.com/alexmingoia/koa-router https://github.com/saadq/koa-combine-routers/tree/next I get 404 Not Found when attempting to use Named Parameters. What am I…
Ben Pingilley
  • 729
  • 1
  • 6
  • 13