Questions tagged [koa-router]

Router middleware for koa.

Router middleware for koa.

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

139 questions
2
votes
1 answer

Use Koa for Server-Sent Events

After having implemented SSE with Express I wanted to do the same with Koa like so: const Koa = require('koa'); const Router = require('koa-router'); const app = new Koa(); const router = new Router(); router.get('/stream', (ctx, next) => { …
Christopher
  • 1,712
  • 2
  • 21
  • 50
2
votes
0 answers

Koa-router with optional character in route

I'm trying to create a route that will act the same for different prefixes: koa-router with multiple prefixes for the same set of routes: /player/:id /players/:id <- Same as above /player/search /players/search <- Same as above Both of those…
Selfish
  • 6,023
  • 4
  • 44
  • 63
2
votes
1 answer

Using koa-jwt with koa-router

I am implementing the a Nextjs service with koa, koa-router and kow-jwt, but I'm confused with the routing setting with them. My project have 2 pages, one is dashboard and the other is login. The dashboard need to pass the verification and the login…
Jimmy Lin
  • 1,481
  • 6
  • 27
  • 44
2
votes
1 answer

How to get post body with Koa-router-forward-request?

I have the koa-router-forward-request set up. I make an axios call to it and that call is forwarded onto an API. I can do get requests and retrieve the information. I can't get post requests working. I want to forward the post request body from the…
Totals
  • 311
  • 2
  • 5
  • 14
2
votes
1 answer

Why ctx.state did not pass to another middleware?

use koa2 ejs koa-router, ejs template how to use another middleware's ctx.state localhost:3000/admin/usermsg admin.get('/usermsg', async(ctx) => { ctx.state.userMsg = { page: Number(ctx.query.page), limit: 4, …
zrd
  • 21
  • 1
  • 2
2
votes
1 answer

Sub-routes not working in separate file with koa-router

My koa@next app have the following structure. I'm using koa-router@next for the routing: ./app.js const Koa = require('koa'); const router = require('koa-router')(); const index = require('./routes/index'); const app = new Koa(); router.use('/',…
Lanti
  • 2,299
  • 2
  • 36
  • 69
2
votes
2 answers

Router is not defined in KOA2

I have two files, one of them is the app.js and the otherone is api.js. In the first file I have : app.use(setHeader) app.use(api.routes()) app.use(api.allowedMethods()) And in api.js I have: import KoaRouter from 'koa-router'; const api =…
nole
  • 1,422
  • 4
  • 20
  • 32
2
votes
2 answers

koa-router not working with generator

I have been struggling to get koa to respond to requests when I use generators. I wrote a test.js app to demonstrate this. var koa = require('koa'); var app = new koa(); var Router = require('koa-router'); var router = new Router(); router.get('/',…
2
votes
1 answer

Why koa-router sends 404?

I'm using a koa-router, koa-views and sequelize. Data comes from a database, but the status = 404. What am I doing wrong? router.get('/', function *() { var ctx = this; yield models.drivers.findAll({ where: { userId:…
Nicolas
  • 75
  • 11
2
votes
3 answers

How can I configure koa-router to run common code before any of a certain group of routes?

I'd like to add some functionality to /module that gets executed for any matching route under that directory. So for a given set of routes: /module/ /module/page /module/things /module/things/:thingid I want code in a router for /module to run for…
JC Ford
  • 6,946
  • 3
  • 25
  • 34
1
vote
1 answer

Match last URL param including slashes in Koa router

I use koa-router, and would like to match part of the URL (potentially) including slashes. For instance, everything that matches /foo/xxx, /foo/yyy, /foo/dir/xxx, and /foo/a/b/c/d. Something like the following, if *path meant the same as ":path but…
Florent Georges
  • 2,190
  • 1
  • 15
  • 24
1
vote
1 answer

GET uncertain amount of request parameters with koa router

if a define a route like this: router.get('/:name/:age', async (ctx, next) => { ctx.body = ctx.params }) when i access the url: http://localhost:3000/vortesnail/18, I'll get: { name: 'vortesnail', age: '18' } Here is my problem: if i access…
vortesnail
  • 31
  • 5
1
vote
0 answers

koa js backend is showing error - DB not connected -how to fix this issue

I am also trying different network connections it returns the same error. Please help I am stuck last 15 days in this error. Oh! last one thing my laptop IP is dynamically changing so what can I do know. this is my mongoose connecter const…
killrer
  • 21
  • 1
1
vote
0 answers

Remove a specific cookie from all request ctx koa?

What is the most effective way for remove a cookie from every request / reponse on node.js with koa ? I want to remove it everywhere, even on ctx.req , ctx.query etc , everything he would appears. i tried with ctx.cookies.set('foo', null); but it's…
zzzdzdzd
  • 11
  • 1
1
vote
1 answer

Using Sequelize findOne returns before function is finished

I am using Koa router, with Sequelize. And I have used Sequelize init, where the model is created as follows: module.exports = (sequelize, DataTypes) => { class User extends Model { static associate(models) { // Associations... } …
Dipanjan
  • 46
  • 5
1 2
3
9 10