-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Better Implementation of Protocol Handling #43
Comments
i use such functionality in my fork already but its badly hacked code for example i implamented proxy:// |
Hey @frank-dspeed I like this idea a lot. I redesigned diet a while ago specifically with this in mind. That's why we have the protocols folder. I will add WebSocket support soon. If you have a Proposal and working code send me a link and I will look over it. The Protocols should be Third Party modules by the way and you could attach them like this: // server.js
var server = require('diet')
var app = server()
// load websocket protocol
var io = require('diet-protocol-websocket')
io.listen(3000)
// attach websocket protocol to diet
app.protocol(io)
// listen on port 8000
app.listen(8000) Then the Method Listeners will become universal and accept both HTTP and WebSocket requests on the same routes sharing the same API. // routes.js
app.post('/send', function($){
$.end('hello', $.body.name)
}) From the Client you could send data with socket.io simply like this to the // main.js
var socket = io()
socket.send({
method: 'post',
body: {
name: 'John Doe'
}
}) Thanks, |
good proposal but we need to do listen by protocol where some protocols can do multi listen and some need to fail when anything listens already. |
It's wonderful when diet support socket.io or IPC protocol of router, |
@askie i think we have socket.io support at present and also a feathers integration |
@frank-dspeed how to use socket.io and use the same router of diet? var server = require('diet')
var app = server()
app.listen(8000)
var io = require('socket.io')(app.server) // <-- use app.server
io.on('connection', function(socket){
console.log(' ... socket.io: A USER CONNECTED');
});
app.get('/api/get', function($){
$.data.name="john";
$.json();
});` client code: var io = io();
io.on('connection', function(socket){
socket.emit('/api/get',function(a){
console.log(a) // {name:"john"}
} );
}); /api/get is defined by the diet is this adapt? |
@askie thats a totall diffrent issue you open a new 👍 for that kind of questions this is a Proposal for something more advanced. |
@frank-dspeed my idea just like this : https://github.com/finalclass/socket.io-router |
Related #47 |
We should discuss here how to modify diet.js to handle simply all protocols via the current protocol/name shema
--- needed Modifications
maybe a method for registring protocol handlers by name in the app object as like
app.protocolHandler('http', '/app/protocol/http.js')
app.listen('http://host.tld')
The text was updated successfully, but these errors were encountered: