/r/koajs
next generation web framework for node.js
next generation web framework for node.js
/r/koajs
how to use res.on(); in >>>>>>>>>>>>>>>>>>>>>>>>>> KOA framwork nodejs
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?
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!
In Gitter nobody is active can Koa make GitHub discussions?
If I store the user data on ctx.state.user how do I reverse that? ctx.sate.user = null?
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!
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
A shopify app should have the following flow:
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?
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
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.
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.?
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?
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!
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.
Just as the title says, I made a Discord server for Koa.js! You can join here: https://discord.gg/Sx9NDHS :)
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?