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

fixing url manipulation #78

Closed
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/event-stream/event-stream.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class EventStreamService {

async getStreams(): Promise<EventStream[]> {
const response = await lastValueFrom(
this.http.get<EventStream[]>(`${this.baseUrl}/eventstreams`, {
this.http.get<EventStream[]>(new URL('/eventstreams', this.baseUrl).href, {
...basicAuth(this.username, this.password),
}),
);
Expand All @@ -175,7 +175,7 @@ export class EventStreamService {
if (stream) {
const patchedStreamRes = await lastValueFrom(
this.http.patch<EventStream>(
`${this.baseUrl}/eventstreams/${stream.id}`,
new URL(`/eventstreams/${stream.id}`, this.baseUrl).href,
{
...streamDetails,
},
Expand All @@ -189,7 +189,7 @@ export class EventStreamService {
}
const newStreamRes = await lastValueFrom(
this.http.post<EventStream>(
`${this.baseUrl}/eventstreams`,
new URL('/eventstreams', this.baseUrl).href,
{
...streamDetails,
},
Expand All @@ -204,15 +204,15 @@ export class EventStreamService {

async deleteStream(id: string) {
await lastValueFrom(
this.http.delete(`${this.baseUrl}/eventstreams/${id}`, {
this.http.delete(new URL(`/eventstreams/${id}`, this.baseUrl).href, {
...basicAuth(this.username, this.password),
}),
);
}

async getSubscriptions(): Promise<EventStreamSubscription[]> {
const response = await lastValueFrom(
this.http.get<EventStreamSubscription[]>(`${this.baseUrl}/subscriptions`, {
this.http.get<EventStreamSubscription[]>(new URL('/subscriptions', this.baseUrl).href, {
...basicAuth(this.username, this.password),
}),
);
Expand All @@ -221,10 +221,13 @@ export class EventStreamService {

async getSubscription(subId: string): Promise<EventStreamSubscription | undefined> {
const response = await lastValueFrom(
this.http.get<EventStreamSubscription>(`${this.baseUrl}/subscriptions/${subId}`, {
validateStatus: status => status < 300 || status === 404,
...basicAuth(this.username, this.password),
}),
this.http.get<EventStreamSubscription>(
new URL(`/subscriptions/${subId}`, this.baseUrl).href,
{
validateStatus: status => status < 300 || status === 404,
...basicAuth(this.username, this.password),
},
),
);
if (response.status === 404) {
return undefined;
Expand All @@ -234,7 +237,7 @@ export class EventStreamService {

async deleteSubscription(subId: string) {
await lastValueFrom(
this.http.delete(`${this.baseUrl}/subscriptions/${subId}`, {
this.http.delete(new URL(`/subscriptions/${subId}`, this.baseUrl).href, {
...basicAuth(this.username, this.password),
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function bootstrap() {
const password = config.get<string>('ETHCONNECT_PASSWORD', '');
const factoryAddress = config.get<string>('FACTORY_CONTRACT_ADDRESS', '');

const wsUrl = ethConnectUrl.replace('http', 'ws') + '/ws';
const wsUrl = new URL('/ws', ethConnectUrl.replace('http', 'ws')).href;

app.get(EventStreamService).configure(ethConnectUrl, username, password);
app.get(EventStreamProxyGateway).configure(wsUrl, topic);
Expand Down
12 changes: 6 additions & 6 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ export class TokensService {
async getReceipt(id: string): Promise<EventStreamReply> {
const response = await this.wrapError(
lastValueFrom(
this.http.get<EventStreamReply>(`${this.baseUrl}/reply/${id}`, {
this.http.get<EventStreamReply>(new URL(`/reply/${id}`, this.baseUrl).href, {
validateStatus: status => status < 300 || status === 404,
...basicAuth(this.username, this.password),
}),
Expand All @@ -838,10 +838,10 @@ export class TokensService {
class TokenListener implements EventListener {
private readonly logger = new Logger(TokenListener.name);

constructor(private readonly service: TokensService) { }
constructor(private readonly service: TokensService) {}

async onEvent(subName: string, event: Event, process: EventProcessor) {
let signature = this.trimEventSignature(event.signature)
let signature = this.trimEventSignature(event.signature);
switch (signature) {
case tokenCreateEventSignature:
process(await this.transformTokenPoolCreationEvent(subName, event));
Expand Down Expand Up @@ -897,11 +897,11 @@ class TokenListener implements EventListener {
}

private trimEventSignature(signature: string) {
let firstColon = signature.indexOf(":")
let firstColon = signature.indexOf(':');
if (firstColon > 0) {
return signature.substring(firstColon + 1)
return signature.substring(firstColon + 1);
}
return signature
return signature;
}

private async transformTokenPoolCreationEvent(
Expand Down