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

Merge project with socket-controllers #106

Closed
pleerock opened this issue Apr 3, 2017 · 13 comments
Closed

Merge project with socket-controllers #106

pleerock opened this issue Apr 3, 2017 · 13 comments
Labels
type: discussion Issues discussing any topic.

Comments

@pleerock
Copy link
Contributor

pleerock commented Apr 3, 2017

I have a plans to merge into this library socket-controllers library. Your thoughts about this decision? adding @19majkel94

@MichalLytek
Copy link
Contributor

MichalLytek commented Apr 3, 2017

Actually, it's not a library but framework 😉 IoC and other blah blah definitions.

I'm into cooperation of routing- and socket-controllers but I'm not sure about merging this together. They are designed for different purposes and I can't imagine that you force koa users to get routing-controllers from npm together with sockets like you don't want to set express and koa as dependencies in package.json.

I see only one use-case scenario with integration - mixed controllers. Not mixed parameters in class methods (it makes no sense) but one controller with REST API methods for HTTP and socket endopoint for push notification about changes from other users on this resource.

I'm not sure how much routing-controllers and socket-controllers codebases have in common and how to detect which method belong to which "library" - additional decorator is an inelegant solution, looks as bad as separate controllers.

@idchlife
Copy link

idchlife commented Apr 3, 2017

Guys I'm new here, fascinated by routing-controllers (my god @pleerock you are one magnificent sir for doing ORM like Doctrine and this controllers with decorators in TypeScript) and going to use it in the nearest projects, but what is socket-controllers? Where are they?

@pleerock
Copy link
Contributor Author

pleerock commented Apr 4, 2017

@idchlife there you are this lib to use socket.io library with decorators

@idchlife
Copy link

idchlife commented Apr 4, 2017

Oh, thanks!

About topic, I guess one way is not to merge them making "routing+socket-controlles" but to create third library that will provide functionality for making a project with just choosing dependency like express or koa under the hood, allowing you to use it like a standalone framework for building projects. Maybe even with DI and TypeORM already attached/installed, for more convenient way to create projects using TypeScript + decorators at full power.

Because not everyone needs sockets with common routing or routing with sockets. That's why there are 2 separate libraries that for different functionality.

@pleerock
Copy link
Contributor Author

pleerock commented Apr 4, 2017

Maybe even with DI and TypeORM already attached/installed, for more convenient way to create projects using TypeScript + decorators at full power.

there is now discussion about complete framework (you can find sample here which contains everything-in-one.

Because not everyone needs

thats something very hard to achieve. Because sometimes people need, sometimes they not... There is multer, session and some libraries used by this lib, but sometimes people don't need uploading. Even if I merge socket controllers into routing controllers in a separate framework - same question arrises there - maybe not all people need that.

@MichalLytek
Copy link
Contributor

MichalLytek commented Apr 4, 2017

There is multer, session and some libraries used by this lib, but sometimes people don't need uploading.

But they are hidden peer dependencies - you are not forced to install it if you don't use it. But there must be some code in routing-controllers codebase to provide support if it needs deep integration to work.

I don't mind about extension to integrate sockets into routing-controllers like typeorm-routing-controllers-extensions even it's demand some lines of code to provide interface or methods to integrate.

Even if I merge socket controllers into routing controllers in a separate framework - same question arrises there - maybe not all people need that.

There is a difference between framework like Angular or TypeStack, which are a collection of libs which cooperate together to help build big app, and IoC libraries aka framework like routing-controllers which focus only on one part of the app/technology. It's not a problem to deliver the gorilla and the entire jungle but it's bad when user only want the banana.

@laukaichung
Copy link

laukaichung commented Apr 7, 2017

I'm fine with either an extension or merge. I've been longing for some sort of bridge between socket.io and routing controller. #100

@pleerock
Copy link
Contributor Author

I decided not to merge them for now. Plan is to allow typestack cli to generate project with or without socket-controllers enabled.

@dulichan
Copy link

dulichan commented Jun 13, 2017

Is there an example that uses both these? I am using the below code sample

 this.app = express();
    const exp = this.app;
    this.configuration(ENVIRONMENT);
    this.app = require("http").Server(this.app);
    this.io = require("socket.io")(this.app);

    this.app = useExpressServer(exp, {
      routePrefix: "/v1",
      defaultErrorHandler: false,
      middlewares: [BoomMiddleware],
      authorizationChecker: authorization,
      controllers: [__dirname + "/connectors/**/mock/*.js"]
    });
    useSocketServer(this.io, {

    });

Socket.io gives a 404 for the above configuration. If I remove router controllers it works fine.

@pleerock
Copy link
Contributor Author

pleerock commented Jun 13, 2017

specify controllers for socket controllers in options as well

@dulichan
Copy link

dulichan commented Jun 13, 2017

@pleerock I specified it (earlier I manually imported it before useSocketServer) but I am getting the same error. I am also attaching a screenshot of my backend error log.

XMLHttpRequest cannot load http://localhost:9000/socket.io/?id=83&EIO=3&transport=polling&t=LoXMf_w. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4300' is therefore not allowed access. The response had HTTP status code 404.

screen shot 2017-06-13 at 5 39 39 pm

@dulichan
Copy link

I figured out the mistake I made. Posting the answer to anyone who encounters it. The mistake I made was assigning the express instance returned by useExpressServer to this.app.

    this.app = express();
    this.exp = this.app;
    this.app = require("http").Server(this.app);
    this.io = require("socket.io")(this.app);

    useSocketServer(this.io, {
      controllers: [__dirname + "/controllers/event/*.js"]
    });
    useExpressServer(this.exp, {
      routePrefix: "/v1",
      defaultErrorHandler: false,
      middlewares: [BoomMiddleware],
      authorizationChecker: authorization,
      controllers: [__dirname + "/connectors/**/mock/*.js"]
    });
   this.app.listen(PORT, () => {});

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: discussion Issues discussing any topic.
Development

No branches or pull requests

5 participants