-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RestServer and Socket.io #4496
Comments
@TheZwieback Can you build on top of https://github.com/strongloop/loopback-next/tree/socketio/packages/socketio? |
@raymondfeng I looked at the package and it seems to instantiate a new http server to use in its middleware. It would be nice to just use an existing one, i.e. like the rest server described above. |
@TheZwieback I write some code to solve this problem. I write a mixin called // RevealServerMixin
import { Constructor } from '@loopback/core';
import { CustomRestComponent } from '../services/CustomRestComponent';
import { CustomRestServer } from '../services/CustomRestServer';
export function RevealServerMixin<T extends Constructor<any>>(
BaseClass: T,
) {
class Subclass extends BaseClass {
constructor(...args: any[]) {
super(...args);
this.unbind('components.RestComponent');
this.unbind('servers.RestServer');
this.component(CustomRestComponent);
}
get restServer(): CustomRestServer {
return this.getSync('servers.CustomRestServer');
}
}
return Subclass;
} // CustomRestComponent
import { RestComponent } from '@loopback/rest';
import { Constructor, Server } from '@loopback/core';
import { CustomRestServer } from './CustomRestServer';
export class CustomRestComponent extends RestComponent {
servers: {
[name: string]: Constructor<Server>
} = {
CustomRestServer,
};
} // CustomRestServer
import { RestServer } from '@loopback/rest';
import { HttpServer } from '@loopback/http-server';
export class CustomRestServer extends RestServer {
get httpServer(): HttpServer | undefined {
return this._httpServer;
}
} And in export class MyApplication extends RevealServerMixin(RestApplication)
) {} |
Maybe this can help #4044 |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Hi,
I want to implement a WebSocket server on a loopback rest server. As the rest server is based on an express app with a node http server this should be straight forward. Unfortunately I found a minor issue. Accessing the node http server object is not possible in the RestApplication constructor as it is protected inside the RestServer class. I changed the properties on my machine locally and tested the standard deployment and it works as expected:
Would it be possible to make the base http Server object (this.restServer._httpServer) available through a getter? Using the RestServer instance in the ioServer.attach method does not work.
Thanks and cheers,
Christian
The text was updated successfully, but these errors were encountered: