After a POST request is sent from the browser to the /generate url in the server, I want to create a string and save it as a cookie. When a GET request is later sent from the browser to the /retrieve url in the server, I want to send that string as…
I was wondering how can we catch all API call of a specific route with KOA-Router.
For example. I have an api designed like this :
/api/
/api/user/
/api/user/create
/api/user/login
/api/user/delete
How can I trigger the route /api/ for all calls…
This is the code of route. When I use commented Promise, it returns 123 in body. But with mongoose query it returns 404 status. Item in log founds good. But it seems router just ignore await and return 404 immediately. What am I doing…
I'm using koa2 and koa-router together with sequelize on top. I want to be able to control user access based on their roles in the database, and it's been working somewhat so far. I made my own RBAC implementation, but I'm having some trouble.
I…
I am getting 405 Method Not Found as response when using PUT and DELETE request using POSTMAN.
My app.js file looks like this
const Koa = require('koa');
const serve = require('koa-static');
const cors = require('@koa/cors');
const userRouter =…
I'm trying to define different routes using koa-router and I'm having a hellova time getting it working.
Something like this:
const apiRouter = new KoaRouter({
prefix: '/api'
})
.use(bodyParser)
.post('/sign-in',…
I'm having a problem with koa js and middleware order.
Im' using multiple middlewares, Koa-router, formidable, koa-static-folder and one for setting headers.
Right now, with current order, when I'm uploading a file from the frontend to backend via…
I decided to split my routers by their purpose, so they look like this:
routers/homeRouter.ts
import * as Router from 'koa-router';
const router: Router = new Router();
router
.get('/', async (ctx, next) => {
ctx.body = 'hello world';
…
when I use ctx.redirect, koa just sends GET request but not actually redirect the tab to other page from where It was. I'm just trying to redirect to user's page after signup. Here's code.
signup
router.post('/signup', async (ctx, next) => {
let…
Given two middleware, how can you add something that would get hit first, then determine which of the middleware to pass the request onto. The request can only be dropped or forwarded to one of the middleware, never both.
app.use( function *(next)…
I'm stuck writing an authentication router for a koa app.
I have a module that gets data from the DB then compares it to the request. I want to only run yield next if the authentication passes.
The problem is that the module that communicates with…
I use koa to create a nodejs application, and I try to optimize.
app.js
'use strict';
const Koa = require("koa");
const app = new Koa();
const Router = require("koa-router");
const router = new Router();
const stuff =…
I want to pass a parameter into middleware
router.get(
'/:id',
myMiddlware({projectid : ctx.request.query.projectid } ),
async (ctx) => {...}
)
I need to get the value of 'projectid' in the middleware declaration but of course, ctx from…
So I have this function in Koa, that basically checks if a user can access a specific route.
exports.requireRole = async role =>
async (ctx, next) => {
const { user } = ctx.state.user;
try {
const foundUser = await…