-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http server #1
Comments
Yeah. Should it be inside the main graft package, just because we have all other transports over there? I'm actually inclined to do that, because of completeness. It can also be a module used there though. See GraftJS/graft#8 |
to me this feels more like way to map against other services, not a way for graft <-> graft communication. i also think a case could be made for moving things required like 'graft/spdy' to 'graft-spdy' instead. |
|
Trying to whip up something quick to understand how this will work. Let me know if I am on the right track starting this example off: 'use strict';
var graft = require('graft')();
var http = require('http');
var server = http.createServer(function(req, res) {
graft.write({
req: req,
res: res
});
return graft
.pipe(through.obj(function(msg, enc, cb) {
msg.res.end("Hello World");
cb();
}));
});
server.listen(3000); In terms of an api for the server, any thoughts on what would be better? require('graft-http').server(3000) // <-- returns graft instance for piping, etc.
// this way is more inline with how the spdy/ws servers function or var server = http.createServer(require('graft-http'));
server.listen(3000);
// how do we map micro services to the server at this point. are we assigning services to url endpoints? |
We could do unwrap the req a little bit of before just putting it into the graft channel. Something like having the .path, and .query and .body available on the message itself. As for mapping things... I'm just riffing, but I could imagine something similar to :
|
maybe we should start by getting some more concrete test cases out ? I might have one in aetherboard. |
Yes, some things should definitely get pulled into the message. This way you could do some things like graft
.where({path: '/foo'}, handler); |
@AdrianRossouw check out the draft branch. Currently I am mixing the properties of a graft instance in with an object. Not sure that this is very clean. It is probably better to have graft as a property of the server, and then proxy graft's methods to it ( |
Look at example.js to see how this would look when using. You can do something like |
var app = connect();
var graft = graftHttp();
app.use('/path', graft.pipe(through.obj(function(msg, enc, done) {
}))); Nevermind.. not working. I think by using the proxy method rather than merge object properties this will work. |
Set up proxy methods for Now the above example would actually work. |
There is a problem with the response, you cannot set the headers across machines, as on the other end it will just appear as a standard stream. I think the right message to be sent is something in the line: {
url: ..
path: ...
host: ... // plus all the components
headers: ...
body: ...
handler: handler
}
// on the other side
req.handler.write({
headers: // my headers
statusCode: 422
body: // ...
// other stuff...
}) I'm against hijacking We should consider the use case of |
Ooooo, I like it. Reminds me of rack. |
Was wondering about routing. Do we want to embed something like https://github.com/pillarjs/path-match ? Or leave it up to the user to pick their router of choice. What if we set up methods for standard http methods? graftHttp.get('/post/:id', through.obj(function(msg, enc, done) {}))); |
I think we should dogfood this, and use microservices ;), so we might base it around three steps:
|
Making some progress here. I think I am on the right track. Next up are writing tests. More detail about my progress:
The example will pipe graft to bodyParser.json() and then to a simple echo-er that just spits out whatever was in the body of the request. http client sends a request with I've noticed that middleware love attaching things directly to the request object, so I need a better way to go from http.IncomingMessage -> graft message. My initial thought was to black list properties we don't want, and filter that on the request. More thinking about a router: would you prefer using something similar |
Nevermind that last bit about the router. It will definitely need to be a micro service because when the router parses the route parameters, those will need to be pushed into the stream. |
Router micro service: https://github.com/GraftJS/graft-http/blob/draft/lib/router.js Example has been updated to run when path matches /post/:id |
Last thing I need some opinions on for this server component: When stacking micro services, the return is normally a stream so that you can pipe it through to other micro services. This looks weird in the example, because you see Should we have it be the same as a stream and use pipe? var testService = graftHttp();
testService.use(...);
testService.use(...);
// ^ these get piped together later
testService.listen(); |
I think we should stick to pipe. like : var server = graftHttp();
var testService = server
.pipe(middleware(bodyParser()))
.pipe(middleware(static('/some/dir'));
testService.pipe(route('/post:id')).pipe(handler); |
@AdrianRossouw I think that is not the best approach, piping will slow things down if we pipe too much (let's say we have 20 uservices a message has to pass through at each request, that will be slow). Here is another proposal along the line. var server = graftHttp();
var router = graftRouter();
var testService = server
.pipe(middleware(bodyParser()))
.pipe(router)
.pipe(middleware(static('/some/dir'));
router.route('/post:id', handler); Actually, having a separate graft-router is kind of better than the integrated |
Ahhhh, of course. |
yes!
|
done 👍 https://github.com/GraftJS/graft-http/blob/draft/example.js ok, time for writing tests! |
Gooood! :) |
this is pretty much just a wrapper around http.createServer, that has a graft instance inside of it that it uses to resolve the request.
it will map the response into a returnChannel, and pass the message along.
It should allow you to use all the other stream-oriented http tools that exist, and stay the fsck out of everyone's way as much as possible.
bonus points: be able to pipe messages through a graft http request service, that has been piped into a locally running graft http server =P you know. for tests...
The text was updated successfully, but these errors were encountered: