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


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.

[original thread by Siddhant Agrawal]

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.

[Siddhant Agrawal]

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

[Siddhant Agrawal]

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);
            return problemInspectorServer;

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

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

[Siddhant Agrawal]

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:, 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?

@siddhant-agrawal I see, yes docs look outdated, in 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

[Siddhant Agrawal]

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!