menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

How do I change the server.js file in /backend

January 14, 2020 at 2:10am

How do I change the server.js file in /backend

January 14, 2020 at 2:10am
Hi,
I am following the "Communication via JSON-RPC" docs and am at the point where I have the websocket started but the handler is missing. I believe this is because I am unable to edit the /browser-app/src-gen/backend/server.js file. If I edit this file and build it is replaced by a fresh server.js file. How do I make changes here. Specifically I need to add an import for my new backend service and a container.load() on that service.

January 14, 2020 at 2:53am
You are not supposed to edit this file. It is auto generated bootstrap code.
If you want to do any code customizataions you need a custom Theia extension.
I am trying to create a custom Theia extention. I followed your docs to generate the basic widget extension and I am building on top of that.
ok, it would mean you are missing connection handler binding in the backend module

January 14, 2020 at 9:40pm
import { ContainerModule } from 'inversify';
import { ConnectionHandler, JsonRpcConnectionHandler } from "@theia/core";
import { IProblemInspectorClient, IProblemInspectorServer} from "./problem-inspector-protocol"
export const problemInspectorServerModule = new ContainerModule(bind => {
bind(ConnectionHandler).toDynamicValue(ctx =>
new JsonRpcConnectionHandler<IProblemInspectorClient>("/problem-inspector", client => {
const problemInspectorServer = ctx.container.get<IProblemInspectorServer>(IProblemInspectorServer);
problemInspectorServer.setClient(client);
return problemInspectorServer;
})
).inSingletonScope()
});
I have created the above for the connection handler binding.
and in the server.js I added:
const { problemInspectorServerModule } = require('problem-inspector-extension/lib/browser/problem-inspector-server-module');
container.load(problemInspectorServerModule);
Could you share your code as github repo?
not sure what you mean by and in the server.js i added - you should not modify this file manually
you should expose the backend module in theiaExtensions in your extension package.json, docs should cover it
Edited
Hi Anton, firstly I'd just like to thank you for your help. I am working on getting the code up on a repo so that you may look at it. I am basically trying to follow along this doc: https://theia-ide.org/docs/json_rpc, that will allow me to create a backend that I can call via a websocket and have that trigger a frontend event. At the end of the doc it mentions "Loading the modules in the example backend and frontend" which is why I tried to modify the server.js file. It seems like this is not the way it is done anymore. Could you point me to some docs or an example that has a backend?
I see, yes docs look outdated, in https://theia-ide.org/docs/authoring_extensions/ look at Implementing the Extension
each extension should declare frontend/backend entry points in package.json via theiaExtensions attribute
theia build will analyze these declarations and generate server.js

January 16, 2020 at 7:28pm
I see, I was able to add the backend module into the theiaExtensions attribute and I see it being loaded in server.js. Thank you for your help!