Skip to content
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

Open
frank-dspeed opened this issue May 11, 2016 · 11 comments
Open

Better Implementation of Protocol Handling #43

frank-dspeed opened this issue May 11, 2016 · 11 comments
Assignees
Milestone

Comments

@frank-dspeed
Copy link
Contributor

frank-dspeed commented May 11, 2016

We should discuss here how to modify diet.js to handle simply all protocols via the current protocol/name shema

--- needed Modifications

  • app.protocol looks in /app/protocols/name first then in dietjs so we can overwrite the create server method to return any server we whant to have (net for tcp)

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')

@frank-dspeed
Copy link
Contributor Author

i use such functionality in my fork already but its badly hacked code for example i implamented proxy://
and lb:// protocol with costum http servers that do the job like the name says but i also did mysql:// and other protocols a lot

@adamhalasz
Copy link
Owner

adamhalasz commented Jul 23, 2016

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 GET /send route:

// main.js
var socket = io()
socket.send({
     method: 'post',
     body: {
          name: 'John Doe'
     }
})

Thanks,
Adam

@adamhalasz adamhalasz added this to the Diet v1.0 milestone Jul 23, 2016
@frank-dspeed
Copy link
Contributor Author

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.

@askie
Copy link

askie commented Feb 22, 2017

It's wonderful when diet support socket.io or IPC protocol of router,
diet will adapt to develope a electron app!

@frank-dspeed
Copy link
Contributor Author

@askie i think we have socket.io support at present and also a feathers integration

@frank-dspeed
Copy link
Contributor Author

@askie
Copy link

askie commented Feb 22, 2017

@frank-dspeed how to use socket.io and use the same router of diet?
such as:
server code:

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?

@frank-dspeed
Copy link
Contributor Author

@askie thats a totall diffrent issue you open a new 👍 for that kind of questions this is a Proposal for something more advanced.

@askie
Copy link

askie commented Feb 23, 2017

@frank-dspeed my idea just like this : https://github.com/finalclass/socket.io-router

@frank-dspeed
Copy link
Contributor Author

frank-dspeed commented Feb 23, 2017

@askie @askie thats a totall diffrent issue you open a new 👍 for that kind of questions this is a Proposal for something more advanced.

@adamhalasz adamhalasz changed the title Better Implamentation of Protocol Handling Better Implementation of Protocol Handling Feb 27, 2017
@frank-dspeed
Copy link
Contributor Author

Related #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants