/r/koajs

Photograph via snooOG

next generation web framework for node.js

next generation web framework for node.js

/r/koajs

522 Subscribers

1

Hello every one , I have a one question something KOA steaming system , the question about koa can't use same express framwork, this is ' res.on();'

how to use res.on(); in >>>>>>>>>>>>>>>>>>>>>>>>>> KOA framwork nodejs

0 Comments
2020/12/01
02:14 UTC

3

any good koa cli generator out there?

0 Comments
2020/10/26
17:01 UTC

1

Koa throw error fuction

ctx.throw(400, 'name required', { user: user });

should be the equivalent of this

const err = new Error('name required');
err.status = 400;
err.expose = true;
throw err;

but how do I add a err.message?

2 Comments
2020/08/13
22:51 UTC

1

Some resources

I'm looking forward to learn some Koa. I want to write some backend for shopify apps. So you know any resources like articles or videos where I can learn Koa Js? I want to know how to do Auth and some stuff.

btw, im mainly focused on front-end that's why I'm asking for some backend resources. Thank you!

1 Comment
2020/07/29
18:23 UTC

1

Can Koa make GitHub discussions?

In Gitter nobody is active can Koa make GitHub discussions?

5 Comments
2020/07/19
14:59 UTC

1

How to un-state a user?

If I store the user data on ctx.state.user how do I reverse that? ctx.sate.user = null?

2 Comments
2020/06/19
18:37 UTC

1

ctx.redirect() Sanity Check

Working on my first full-stack application, and finding myself rather lost. I've got a React app on localhost:3000 (which manages routes with react-router), and my Koa app on localhost:4000 (using koa-router).

Let's say I call a POST request (with Fetch) from my React app, it hits a server route:

async myRoute(ctx) {

console.log("in myRoute") // yup, that logs. I made it this far.

ctx.redirect('http://localhost:3000/someroute');

}

Now this triggers a CORS error, which I ( sort of) understand about. But my question is this: even if I deal with the CORS error properly, this `ctx.redirect` method will never cause my React app to change it's local route. Correct?

That is to say, the server on Port4000 has "no authority" over what's happening on Port3000. If I want to change the route in my React app, I'll have to do so from within the React app after getting a message back from the server. The server code above can only redirect the *server* to this route... and since it's not listening on Port3000, it doesn't do anything.

Hoping someone can confirm my understanding, or clarify in the (likely) event that I have a misconception. Thanks for your time!

7 Comments
2020/05/03
19:24 UTC

4

Created a Koa API with a fully fleshed-out user login/signup/forgot/reset authentication system using JWT.

Also added seeded data to get you started please check it out and I welcome any criticism since I am fairly new at JAVASCRIPT GITHUB REPO

3 Comments
2020/03/19
02:54 UTC

1

ctx.json() and ctx.redirect at once?

A shopify app should have the following flow:

  1. Request is made to route "/"
  2. OAuth process is run
  3. Upon success, the client is redirected to an external URL containing a front end React.js app. a JSON object should also be passed containing auth data

Can both a redirect and json object be sent together?

If not, I suspect a cookie should send the data. Is that the best option for this?

1 Comment
2020/02/05
22:34 UTC

1

What does koa.keys = [API_SECRET]; do?

I'm seeing this pattern on a shopify library. But they later pass the api secret key inside a config object. So what is the purpose of the setting the .keys property on the koa server? I guess it has to do with OAuth?

Thanks for any explanation

1 Comment
2020/02/01
09:38 UTC

3

Node.js Koa Framework Crash Course | Basic CRUD App Example

0 Comments
2020/01/15
13:19 UTC

2

Serving static files on specific routes

The last Days I tried to serve static files on specific routes, I read about koa-static, koa-mount and koa-static-server and koa-serve.

I would like to serve on / - a simple web app containing login and a Dashboard

on /entries a specific Entry which consists of a static file.

​

Is there a way I can serve a specific static file on a specific route? I just found middlewares which need to be implemented with app.use, but for this use case I cannot use a middleware I need to send a specific file back to the client.

1 Comment
2019/07/25
11:47 UTC

3

What is this high level "sugar" Koa provides?

Koa Js official documentation (https://koajs.com/) says the following,

... a key design decision was made to provide high level "sugar" at the otherwise low-level middleware layer.

As I understand, koa js does not include any middlewares, So what is this low-level middleware layer.?

1 Comment
2019/04/28
07:47 UTC

2

Changing routing middleware & strategy for route authorization

Yay, first thread in 2 months! Let's see what we'll get.

So I've been happily using koa-router, but I am pretty (to say it mildly) reserved about the author of it having, apparently, removed contributors without contacting them and then putting the middleware for sale. It was bought by some person without much any sort of a public profile.

I'm now checking into an alternative routing middleware to work as my go-to. One thing I'm wondering about is how to cleanly implement route authorization though. I don't want to do authorization in the start of every route, as that's just lots of unnecessary duplicate code in my humble opinion.

One problem with koa-router was that there's no clean way to get the pattern match for an URL before the middleware has ran. After koa-router has ran, it populates the ctx._matchedRoute field. But knowing beforehand what route is going to be matched is non-trivial. So, if you make lists of allowed and non-allowed routes for different access levels, there's a risk that the route in your list is not actually matched the way you thought it would be.

Further, lists like this:

allowed_routes = ["user/register", "user/forgot_password" ...]

disallowed_routes = ["user/create", "users/list" ...]

..are not very clean anyway. All routes should really be disallowed by default and cleanest would be if the route definition itself also allowed for the definition of its access level and if you could do a check against this access level before moving to the route function.

So - any thoughts about how to do this cleanly with e.g. koa-better-router or some other routing middleware?

2 Comments
2019/04/25
12:18 UTC

2

Use find-my-way in Koa

0 Comments
2019/02/21
17:16 UTC

3

Boilerplate? Recommended Setup (Hot Reload, Testing, etc)

Hey All,

​

I am just getting into node.js and am looking for a good starter point to get my koa project setup. Do people have any recommendations for a boilerplate/starter kit or a good base set of node.js tools to install? (babel, webpack, etc). I am looking to build a RESTAPI (or GraphQL) with a React and React Native Frontend (bootstrap maybe?) using Passport.js for authentication and Postgres with Knex.js for Databases.

​

I have seen ReactQL (which uses Koa), koa-react-starter, koa-es7-boilerplate, koa web kit,... recommendations? Others?

​

Thanks!

1 Comment
2019/01/20
13:41 UTC

6

Its promise based core is very attractive, however, I am still not sure wether I can commit to it for a commercial project.

I am deeply attracted by KOA's promise core. I am starting a new large scale commercial web platform.

I'm wondering if KOA is ready now, in 2018, especially weather the important packages used in Express support KOA.

It will be a very long and serious commitment to KOA framework, thus the reason I'm very cautious atm. Would you choose KOA over Express now? Or would you recon I still choose Express for the moment.

7 Comments
2018/10/15
14:19 UTC

5

Koa.js Discord server

Just as the title says, I made a Discord server for Koa.js! You can join here: https://discord.gg/Sx9NDHS :)

1 Comment
2018/08/27
00:13 UTC

2

koa-router, example on docs

according to the tutorial, app.use(router.routes()).use(router.allowedMethods()); is placed at the end of declaring routes. Why not before where middle ware is normally placed?

3 Comments
2018/05/08
21:49 UTC

2

Inquiry:I'm upgrading to SH 31 and the only missing resource is 1000 Nobel badges. Is it possible to buy thes budges by gold during the upgrade as i already have all other resources? Appreciate your response.

1 Comment
2017/10/02
09:13 UTC

Back To Top