Comments (9)
Thank you for your message, Carlos.
Couple questions:
- Do you need to use HTTP and Sockets or just sockets?
- Can you please send a PR with your changes so I can see exactly what you are trying to do. The intent is not to merge but better understand what flexibility you need.
I think the clean way here is to restructure things so that such extensions are possible in a modular way and I am very open to doing it.
Thanks
from nodebootstrap.
Hi @inadarei,
Thank you for your quick answer. I still did not find the best way to really modularise the application, and this is the point where I am stuck. These are the modifications I did on the nodebootstrap-server/app.js:
...
, http = require('http');
...
if (is_http_thread) {
http = http.createServer(app);
http.listen(CONF.app.port);
}
...
...
callback(app, http);
...
Then, in the server.js
file I used the http handler to bind socket.io:
var io = require('socket.io')(http);
// Use example directly from the server.js file. It should be used in the modules.
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('a user disconnected')
})
});
However, now the problem that I am facing is that I would like to use my socket.io io
object on the individual modules without braking the no-global-variables rule. At this point I have these doubts:
- I am not really sure if I should find a way to bind socket.io in the module itself. Maybe finding the http server and creating a new
http
instance? However, it feels awkward. - I guess I am facing this issue because I did not actually understand how modules can
require('express')
and create a newapp
that would be exported to the main app using the module. This approach, tough it is really nice to modularise the app, makes it impossible to use any configuration from the main app in the modules.
How would you get socket.io to work in the modules?
Thank you,
Carlos.
from nodebootstrap.
Thank you Carlos.
Work on making NodeBootstrap to be more modular is well on its way and I hope to be able to support your use case soon.
Appreciate all your information.
from nodebootstrap.
+1
from nodebootstrap.
+1
from nodebootstrap.
how does something like the following look: https://github.com/inadarei/nodebootstrap/blob/master/server.js#L13
Since websockets are not URL-path-driven and are event-driven, we don't actually need to do as much "magic" as we had with the callback support for HTTP routes. Each module just needs access to socketio instance and it can be passed-through during module initialization. Multiple modules can/should share the same instance as in the event-driven workflow, multiple modules are "allowed" to respond to the same event.
All you should need is: pass websockets instance to the module, during inclusion.
Sounds OK?
from nodebootstrap.
Exactly what I have been doing. However, I think you may have meant to write runningApp.http
(https://github.com/inadarei/nodebootstrap-server/blob/master/app.js#L40)?
On Mon, Apr 13, 2015, 00:03 Irakli Nadareishvili [email protected]
wrote:
@carlosbaraza https://github.com/carlosbaraza @feynmanliang
https://github.com/feynmanlianghow does something like the following look:
https://github.com/inadarei/nodebootstrap/blob/master/server.js#L13Since websockets are not URL-path-driven and are event-driven, we don't
actually need to do as much "magic" as we had with the callback support for
HTTP routes. Each module just needs access to socketio instance and it can
be passed-through during module initialization. Multiple modules can/should
share the same instance as in the event-driven workflow, multiple modules
are "allowed" to respond to the same event.All you should need is: pass websockets instance to the module, during
inclusion.Sounds OK?
—
Reply to this email directly or view it on GitHub
#26 (comment)
.
from nodebootstrap.
Hi @inadarei,
This is the way I was doing too, passing the io object around.
I am glad this idea made all its way to master :D.
from nodebootstrap.
Awesome! Sounds great. Glad that websockets it nicely supported now. Thanks, guys!
@feynmanliang, yes the code sample was supposed to have runningApp.http
. Good catch! I updated the file, now. Thank you.
from nodebootstrap.
Related Issues (20)
- Deprecated dependencies
- Error shows up during project build on Windows PC HOT 1
- while building the hello project throws error HOT 1
- build Error - Firewall ? HOT 4
- Integrate helmet.js HOT 1
- Consider using https://github.com/tj/consolidate.js HOT 2
- NodeBootstrap Users
- maxBuffer Exceeded Error HOT 2
- Get intellij recognize module structure HOT 1
- npm run dev only works when executed using root HOT 5
- Nodejs version control for Dockerfile HOT 2
- What port does forever (start.sh) run the server on? HOT 6
- API mode vs. APP mode. HOT 1
- Run on https HOT 2
- Unable to run container HOT 3
- Document Docker Dependencies? HOT 2
- ENOENT error HOT 4
- Add option for es6 coding style HOT 3
- Exception when installing in the current folder
- Template string for less code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodebootstrap.