-
-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Koa Feathers transport #942
Comments
Thank you for starting this @christopherjbaker! Some notes on this from me:
I don't think we should try and make Express middleware work. I did see koa-connect which has a big warning to only use it when absolutely needed. |
From @christopherjbaker on October 2, 2017 17:55 Having each provide their own |
From @kristianmandrup on October 14, 2017 21:16 Very happy to see this issue! Let's collaborate! I've come pretty far already on the REST side. Cheers! |
From @kristianmandrup on October 15, 2017 18:54 @christopherjbaker I've come really far with a much more extensible approach (I think). Would love some feedback and assistance to finish it off ;) |
Sounds great @daffl :) I'd love to see this working out. I'm currently busy building a React app and not using FeathersJS for the time being. Would love to see it targeted more towards a micro services approach such as one service per Kubernetes pod or one endpoint per AWS lamda function or similar. Deploying a pure old-school REST only server with all endpoints in a huge monolith seems like an ancient approach by now IMO. What is the latest FeathersJS shaping up to be? Cheers! |
This issue is more intended for creating a Feathers transport adapter for Koa. There is a more recent microservice discussion in #939. |
From @christopherjbaker on September 30, 2017 22:23
I'm not sure this is the right place to add this issue, but I'm not sure where would be better.
With prompting from @marshallswain, I've been working on a feathers-koa (very early, mostly proof-of-concept), to complement this package. I have been running into some issues, however, primarily as much of the feathers code is expecting things to follow express conventions, which koajs (obviously) does not. Some of these are more easily surmountable (though hacky) than others. I am hoping we can come up with a solution that works well with both.
First, the issues:
All of the places that feathers passes a middleware function to app.use, that middleware takes the form
function(req, res, next)
(as express does). Koa middleware takes the formfunction({ request, response, req, res }, next)
(wherereq
andres
are the node-native objects, andrequest
andresponse
are helper objects with QOL methods which accessreq
/res
). This was surmounted by modifying the middleware methods before passing them on. While this works, it feels very hacky.feathers-rest makes use of an
app.route
method, which returns an object containingget
,post
, etc. I added a router to koa (as it does not contain one in the core) and built a method which returns a similar object (each of which had to be passed toexpressifyMiddleware
).Some are proving to be more difficult to overcome, however. The
req
andres
objects provided by express are the native ones, with some extras added. My first thought was to modify feathers-rest to not use those helpers and thus be compatible with the native objects. This worked forres.status(x)
(res.statusCode = x
) andres.format()
(removed, as it isn't really accomplishing anything).req.params
,req.query
,req.body
, andreq.json
are not native, however. They could be emulated by modifying thereq
/res
objects before passing them in, just like express does.I was wondering if you had a preferred approach to this. While I could do a wrapper like express does, and apply
expressifyMiddleware
all over the place, that is not very forward compatible (express could change, request 5 could have a different api, other frameworks would expect a third set of requirements, etc). My thoughts here would be for feathers modules to only use native methods, and any needed helpers to be applied to those native objects by feathers, and to ignore (or preferably remove entirely) those provided by express/koa/etc. I think some of these would be provided by feathersjs (res.status()
(possibly just useres.statusCode
instead), req.params,
req.query, 'req.body
), and others by feathers-express, feathers-koa, and feathers- as needed (res.json()
).Copied from original issue: feathersjs-ecosystem/express#3
The text was updated successfully, but these errors were encountered: