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

Prepare v1.0.2 #1063

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/host/src/lib/cpm-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,12 @@ export class CPMConnector extends TypedEmitter<Events> {
headers: http.OutgoingHttpHeaders | Record<string, string> = {}
): http.ClientRequest {
//@TODO: Disconnecting/error handling
this.logger.info("make HTTP Req to CPM", `${this.cpmUrl}/api/v1/cpm/${this.cpmId}/api/v1/${reqPath}`);
const url = `http://scramjet-space/api/v1/cpm/${this.cpmId}/api/v1/${reqPath}`;

this.logger.info("make HTTP Req to CPM", url);

return http.request(
`http://scramjet-space/api/v1/cpm/${this.cpmId}/api/v1/${reqPath}`,
url,
{ method, agent: this.verserClient.verserAgent, headers }
);
}
Expand Down
24 changes: 11 additions & 13 deletions packages/host/src/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,22 +740,20 @@ export class Host implements IComponent {
const clientRequest = this.cpmConnector?.makeHttpRequestToCpm(req.method!, url, req.headers);

if (clientRequest) {
clientRequest.on("socket", (socket) => {
clientRequest.on("response", (response: IncomingMessage) => {
response.on("end", () => {
this.logger.info("Space response ended", url, response.statusCode);
});

res.writeHead(response.statusCode!, response.statusMessage || "", response.headers);

socket.pipe(res.socket!);
}).on("error", (error) => {
this.logger.error("Error requesting CPM", error);
clientRequest.on("response", (response: IncomingMessage) => {
response.on("end", () => {
this.logger.info("Space response ended", url, response.statusCode);
});

clientRequest.flushHeaders();
req.socket.pipe(socket);
res.writeHead(response.statusCode!, response.statusMessage || "", response.headers);

response.pipe(res);
}).on("error", (error) => {
this.logger.error("Error requesting CPM", error);
});

clientRequest.flushHeaders();
req.pipe(clientRequest);
} else {
res.statusCode = 404;
res.end();
Expand Down
2 changes: 1 addition & 1 deletion packages/host/src/lib/serviceDiscovery/sd-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class ServiceDiscovery {
* Returns topic with given configuration, if not exists creates new one.
*
* @param {DataType} config Topic configuration.
* @param {string} [localProvider] Provider identifier. It not set topic will be considered as external.
* @returns added topic data.
*/
createTopicIfNotExist(config: DataType) {
Expand All @@ -94,6 +93,7 @@ export class ServiceDiscovery {
throw new Error("Content-type mismatch");
}
this.logger.debug("Topic routed:", config);

return topic;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/host/src/lib/serviceDiscovery/topicRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class TopicRouter {

const topic = this.serviceDiscovery.createTopicIfNotExist({ topic: topicId, contentType });

await this.serviceDiscovery.update({
contentType,
topicName: topicId.toString(),
status: "add"
});

return {
opStatus: ReasonPhrases.OK,
id: topic.id(),
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/messages/sth-topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type AddSTHTopicEventData = BaseSTHTopicEventData & {
} & (
{ requires: string; provides?: never }
| { provides: string; requires?: never }
| { requires?: never; provides?: never }
);

export type RemoveSTHTopicEventData = BaseSTHTopicEventData & {
Expand Down
Loading