Skip to content

Commit 288da33

Browse files
committed
fix
1 parent 867205e commit 288da33

File tree

4 files changed

+83
-18
lines changed

4 files changed

+83
-18
lines changed

components/server/src/api/server.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import * as http from "http";
8+
import * as express from "express";
9+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
10+
import { inject, injectable } from "inversify";
11+
import { APITeamsService } from "./teams";
12+
import { APIUserService } from "./user";
13+
import { ConnectRouter } from "@bufbuild/connect";
14+
import { expressConnectMiddleware } from "@bufbuild/connect-express";
15+
import { UserService as UserServiceDefinition } from "@gitpod/public-api/lib/gitpod/experimental/v1/user_connectweb";
16+
import { TeamsService as TeamsServiceDefinition } from "@gitpod/public-api/lib/gitpod/experimental/v1/teams_connectweb";
17+
18+
@injectable()
19+
export class API {
20+
@inject(APIUserService) protected readonly apiUserService: APIUserService;
21+
@inject(APITeamsService) protected readonly apiTeamService: APITeamsService;
22+
23+
public listen(port: number): http.Server {
24+
const app = express();
25+
this.register(app);
26+
27+
const server = app.listen(9877, () => {
28+
log.info(`Connect API server listening on port: ${port}`);
29+
});
30+
31+
return server;
32+
}
33+
34+
private register(app: express.Application) {
35+
app.use(
36+
expressConnectMiddleware({
37+
routes: (router: ConnectRouter) => {
38+
router.service(UserServiceDefinition, this.apiUserService);
39+
router.service(TeamsServiceDefinition, this.apiTeamService);
40+
},
41+
}),
42+
);
43+
}
44+
}

components/server/src/api/teams.spec.db.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,35 @@
33
* Licensed under the GNU Affero General Public License (AGPL).
44
* See License.AGPL.txt in the project root for license information.
55
*/
6+
import { suite, test } from "mocha-typescript";
7+
import { APIUserService } from "./user";
8+
import { Container } from "inversify";
9+
import { testContainer } from "@gitpod/gitpod-db/lib";
10+
import { WorkspaceStarter } from "../workspace/workspace-starter";
11+
import { UserService } from "../user/user-service";
12+
import { BlockUserRequest, BlockUserResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/user_pb";
13+
import { User } from "@gitpod/gitpod-protocol";
14+
import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib";
15+
import { Workspace } from "@gitpod/gitpod-protocol/lib/protocol";
16+
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
17+
import { v4 as uuidv4 } from "uuid";
18+
import { ConnectError, Code } from "@bufbuild/connect";
19+
import * as chai from "chai";
20+
21+
const expect = chai.expect;
22+
23+
@suite()
24+
export class APITeamsServiceSpec {
25+
private container: Container;
26+
27+
async before() {
28+
this.container = testContainer.createChild();
29+
this.container.bind(APIUserService).toSelf().inSingletonScope();
30+
}
31+
32+
@test async getTeam_respondsWithTeamMembersAndInvite() {
33+
const sut = this.container.get<APIUserService>(APIUserService);
34+
35+
const;
36+
}
37+
}

components/server/src/container-module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ import { spicedbClientFromEnv, SpiceDBClient } from "./authorization/spicedb";
114114
import { Authorizer, PermissionChecker } from "./authorization/perms";
115115
import { EnvVarService } from "./workspace/env-var-service";
116116
import { APIUserService } from "./api/user";
117-
import { APITeamService } from "./api/teams";
117+
import { APITeamsService } from "./api/teams";
118+
import { API } from "./api/server";
118119

119120
export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
120121
bind(Config).toConstantValue(ConfigFile.fromFile());
@@ -318,5 +319,6 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
318319

319320
// grpc / Connect API
320321
bind(APIUserService).toSelf().inSingletonScope();
321-
bind(APITeamService).toSelf().inSingletonScope();
322+
bind(APITeamsService).toSelf().inSingletonScope();
323+
bind(API).toSelf().inSingletonScope();
322324
});

components/server/src/server.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { TeamsService as TeamsServiceDefinition } from "@gitpod/public-api/lib/g
5858
import { APIUserService } from "./api/user";
5959
import { ConnectRouter } from "@bufbuild/connect";
6060
import { APITeamsService } from "./api/teams";
61+
import { API, APIServer } from "./api/server";
6162

6263
@injectable()
6364
export class Server<C extends GitpodClient, S extends GitpodServer> {
@@ -99,8 +100,7 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
99100
protected iamSessionApp?: express.Application;
100101
protected iamSessionAppServer?: http.Server;
101102

102-
@inject(APIUserService) protected readonly apiUserService: APIUserService;
103-
@inject(APITeamsService) protected readonly apiTeamService: APITeamsService;
103+
@inject(API) protected readonly api: API;
104104
protected apiServer?: http.Server;
105105

106106
protected readonly eventEmitter = new EventEmitter();
@@ -399,20 +399,7 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
399399
});
400400
}
401401

402-
{
403-
const apiApp = express();
404-
apiApp.use(
405-
expressConnectMiddleware({
406-
routes: (router: ConnectRouter) => {
407-
router.service(UserServiceDefinition, this.apiUserService);
408-
router.service(TeamsServiceDefinition, this.apiTeamService);
409-
},
410-
}),
411-
);
412-
this.apiServer = apiApp.listen(9877, () => {
413-
log.info(`Connect API server listening on: ${<AddressInfo>this.apiServer!.address()}`);
414-
});
415-
}
402+
this.apiServer = this.api.listen(9877);
416403

417404
this.debugApp.start();
418405
}

0 commit comments

Comments
 (0)