Questions tagged [koa-router]

Router middleware for koa.

Router middleware for koa.

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

139 questions
0
votes
1 answer

How can I split my koa routes into separate files? Middleware problem

Am trying to split koa routes into separate files. I'm having folder structure like this for routes. routes/ __index.js auth.js user.js So if trying with method one means it's working perfectly. But going with dynamic way that is method 2…
Gopu
  • 1
  • 1
0
votes
1 answer

Make ctx.assert response in JSON

I have a few ctx.assert in my code, something like: ctx.assert(db && fb && ObjectId, 400, 'Email validation config error') If that assert fails, my response will be "Email validation config error" as string, but I would like to get a response in…
Fabio Sousa
  • 261
  • 1
  • 2
  • 11
0
votes
1 answer

Koa ctx.query validation before calling handler

I have a basic route that implements the following: router.get('/twitter/tweets', async (ctx) => { const { limit, page, search } = ctx.query ctx.body = { tweets: await twitter.all(limit, page, search), } }) The problem I have is with…
StuartM
  • 6,743
  • 18
  • 84
  • 160
0
votes
2 answers

Koa-Router : Skip the route if the request not in XHR

I have a Rest API made with Koa with some routes, but, at the same time, it will serve my Front (made with a JS framework and its own router). The fact is, when I access from a browser "localhost/user" I want to display the front but when I reach…
Simon Trichereau
  • 721
  • 11
  • 19
0
votes
1 answer

How to duplicate and forward a request with koa router

For several reasons, I have a server that has to forward requests to another server. The response should be the response of the final server. I also need to add an extra header onto the request but remove this header again from the response before…
Fred Johnson
  • 2,539
  • 3
  • 26
  • 52
0
votes
1 answer

is new Router() and Router() identical in koa-router?

I saw the code that uses koa-router as below. const Router = require('koa-router') const routerWithoutNew = Router() I thought it was an error, but I was surprised to see it working properly. const Router = require('koa-router') const…
0
votes
0 answers

POST request body is undefined using koa-body

Its my first time trying to do a POST request with Postman using Koa in my application. I have the router and the body parser but for some reason i still get an error message sayng that my request body is undefined. I think the body parser is not…
grrrrrr
  • 11
  • 2
0
votes
2 answers

How to set up graphql-upload with koa-graphql?

Currently using koa-graphql to set up a graphql server with koa router, attempting to connect graphql-upload to it so I can upload files, however I'm getting an empty object when sending a file through a mutation server.js import…
Kevin Mangal
  • 230
  • 1
  • 3
  • 14
0
votes
1 answer

How to route URL's with koa-router

I am trying to route a URL which I am calling fetch on to a function using koa-router. The URL ends with /email/example@example.com, and is supposed to fetch a user object by their email. The router object defines: router.get(…
0
votes
1 answer

How to print request body in Koa

I have an app where I need to send data from React frontend to Koa server. Problem is that I have no idea how to print out request body in Koa. In React I run this code on click fetch("/metafield", { method: "POST", body:…
Mileta Dulovic
  • 1,036
  • 1
  • 14
  • 33
0
votes
1 answer

Node - Koa Dynamic Route based on url

The goal is to have routes like this - /names/A for every letter all the way through Z. Instead of having 26 html pages for each letter, I want to have one dynamic html page that will show the information for the letter in the url. I am attempting…
Linx
  • 753
  • 3
  • 15
  • 34
0
votes
0 answers

Why is the css no longer loaded if I add a key to the url?

My app is in Koa JS. The code below generates a website with full css (http://localhost:3000/product): module.exports = (router, productsLoader) => { router.get("/product", async ctx => { const product = await…
Alex Luk
  • 41
  • 9
0
votes
2 answers

Localized routes in koa

I'm developing a site with multiple languages. Some routes will therefore also have to be localized and I'm not sure how to do this properly. I'm using @koa/router for routing. For this example it's only English and Swedish but the site will handle…
Magnus Jonsson
  • 123
  • 1
  • 5
0
votes
1 answer

Get mapped route parameters in all-route middleware Koa-router

I'm writing a library that adds validation to all routes, for use with koa-router. In my routes/index.js file, before running any routes, I'm able to get most of what I want to achieve by using the following code: let routePath =…
Ruben Rutten
  • 1,659
  • 2
  • 15
  • 30
0
votes
2 answers

koa-router doesn't work with passport-local strategy

passport.authenticate from koa-passport doesn't work with local strategy. I use no sessions, no serializing. It's just simple passport example, but the server response is always 404. const Koa = require('koa'); const bodyParser =…