Questions tagged [koa]

Koa is a web framework which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Koa is a web framework for Node.js, designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Use this tag if your question is about the application middleware generators and its cascading properties or the use of App.Settings. Note also the existence of the tag if you're using the middleware API with async/await.

Resources

1232 questions
16
votes
2 answers

how to allow Access-Control-Allow-Origin with koa

I'm new to Koa and i encountered a problem that I didnt get when i used epxress. here is my code : const koa = require("koa"); const koaRouter = require("koa-router"); const app = new koa(); const router = new koaRouter(); const cors =…
Jim
  • 669
  • 4
  • 10
  • 24
15
votes
2 answers

Cookie not being set in browser

I am trying to set a cookie which has my auth token in it. I can see it being returned in the response header set-cookie: xxxxxx but for whatever reason, the browser is not storing the cookie. On my react front end http://app1.dev:3001 I am making…
Stretch0
  • 8,362
  • 13
  • 71
  • 133
15
votes
3 answers

How do I mock my config file for testing?

I have a Koa app I just started and I need to test something that grabs data from a config file. I need to test with specific data, but I'm not sure how to modify what data the test receives from the config file. Example: app.js var router =…
hal
  • 4,845
  • 7
  • 34
  • 57
15
votes
1 answer

mocha watching fails under npm

I have a very simple Koa application: var app = module.exports = require("koa")(); app.use(function *(){ this.body = "Koa says Hi!"; }); var port = process.env.PORT || (process.argv[2] || 3000); port = (typeof port === "number") ? port :…
Marcus Hammarberg
  • 4,762
  • 1
  • 31
  • 37
14
votes
4 answers

Import statement breaks typeorm enitities when registered through config.json file

Following official docs, I created small koa/typeorm/postgres app. When I was using createConnection with config, importing entities in the same file, app was working fine, but typeorm cli coudn't find config file so I tried moving config to…
vvAve
  • 177
  • 1
  • 3
  • 13
14
votes
3 answers

Adding to existing library typescript types with a new definition file

I’m using this library https://github.com/chentsulin/koa-bearer-token which adds an extra property to the koa libraries request object like ctx.request.token. So if I use the koa types directly I get an error which tells me the token property…
Dan Webb
  • 535
  • 1
  • 5
  • 12
14
votes
1 answer

How can i get a list of Koa server url routes

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 =…
14
votes
2 answers

How to handle a 404 in Koa 2?

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…
Saad
  • 49,729
  • 21
  • 73
  • 112
14
votes
3 answers

Can I have koa-static serve assets at a custom (e.g., /static/) path?

The docs at https://github.com/koajs/static and my personal experience trying out koa-static lead me to believe that you can only serve files from the root URL of your app. For example: app.use(serve('./some/dir/')); Given the above use of serve,…
orokusaki
  • 55,146
  • 59
  • 179
  • 257
13
votes
2 answers

Koa@2 error handling

I'm building an API with Koa. I have all my routes in place with koa-router. Each route uses a controller that has all the logic for a given mongoose model. I've read the Koa docs on error-handling and understand the use of awaiting in a try/catch…
sansSpoon
  • 2,115
  • 2
  • 24
  • 43
13
votes
2 answers

what's the difference between koa-body vs koa-bodyparser?

I'm developing node server using koa.js I have looked for some libraries for body parser. And there are several kinds of koa body parser. But I don't know what differences btw them including koa-body and koa-bodyparser. Can you explain it? Thank you…
DAESEONG KIM
  • 371
  • 3
  • 12
13
votes
3 answers

Using express middleware in koa

I have existing code which implements an express middleware. How can I use this middleware in a Koa application? When I try to call app.use(expressMiddleware) in order to use the middleware in my Koa app, Koa complains that a generator function is…
urish
  • 8,943
  • 8
  • 54
  • 75
13
votes
2 answers

How to check for error when using yield instead of node-style callback?

I'm wrapping my head around the new ecma6 generators and yield-operator in javascript, specifically in the context of koa. Consider the contrived example: newUser.save(function(err, user) { if(err){ //do something with the error } …
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
12
votes
2 answers

Koa + TypeScript: Property 'body' does not exist on type Request

I wanted to use koa & koa-bodyparser with TypeScript but whenever I access ctx.request.body I get an error that body doesn't exist on type Request import Koa from 'koa' import Router from 'koa-router' import bodyparser from 'koa-bodyparser' const…
user10706046
12
votes
2 answers

Add SSL to Node.js Koa Server?

I'd like to encrypt my Koa server with SSL. It seems simple enough with a regular httpServer, but I'm not how to do it with Koa. Could anyone help?
Taconut
  • 951
  • 4
  • 10
  • 29
1
2
3
82 83