I'm using koa-router.
How can I get the request's query string params?
This is the best I managed to write:
import koaRouter from 'koa-router';
const router = koaRouter({ prefix: '/courses' });
router.get('/', async (ctx) => {
…
I'm trying to figure out how to split my routes into separate files.
I have this so far, but it doesn't work. I just get Not found when I try to access http://localhost:3001/api/things
//server.js
var koa = require('koa');
var app = koa();
var…
I'm developing a mock server using koajs, and i would like to publish a service which lists developed APIs.
I use koa-router for mouting services.
And i would like somethink like:
var business_router =…
I have a 404.jade file that I want to render whenever there is an invalid GET request.
Here is my current code:
app.js
import Koa from 'koa'
import views from 'koa-views'
import serve from 'koa-static'
import rootRoutes from './routes/index'
import…
Why in the following case does koa-static fail to work with koa-router?
const Koa = require("koa")
const serve = require("koa-static")
const Router = require("koa-router")
const app = new Koa()
const router = new Router()
// fails with 404...…
http://localhost:3000/endpoint?id=83 results in 404 (Not Found). All other routes work as expected. Am I missing something here?
router
.get('/', function *(next) {
yield this.render('index.ejs', {
title: 'title set on the server'
…
I'm trying to trigger a download from a POST request handler in Koa with koa-router. Essentially, I'm trying to do something like this:
app.js
const Koa = require('koa')
const router = require('./router')
const app = new…
I have two entities, users and employees. So I want CRUD for both in different endpoints, but both of them will be mounted under "api", so I can define api_v1, api_v2 and so on.
The endpoints would be something like:
get api/users
put…
I have a very simple server to play around with:
import * as http from 'http';
import * as Koa from "koa";
import { Request, Response, Context } from "koa";
import * as Router from "koa-router";
import * as bodyParser from "koa-bodyparser";
const…
I use Koa with Node.js 8.1.
Today I found that in my app.js, if I write in this order:
const Koa = require('koa')
var cors = require('koa-cors')
const app = new Koa()
app.use(cors(options))
app.use(router.routes())
the cors can work. I can verify…
I am newb in Typescript and trying to integrate koa-router and koa-passport. Installed all @types\
import Koa from "koa";
import Route from "koa-router";
import passport from "koa-passport";
import session from "koa-session";
const app = new…
I have a react App. With webpack I build for production. Now I try to set a little koa server to serve the static files generated by webpack for production.
So I did this
import Koa from 'koa'
import serve from 'koa-static'
const app = new…
As part of a migration of an older app from ExpressJs to Koa JS (v1). I've written a piece of middleware to handle any errors that occur. It looks something like this:
module.errors = function * (next) {
try {
yield next;
} catch (err) {
…