Skip to content

Commit bf4ba7c

Browse files
committed
feat(web): ping endpoint
1 parent f688087 commit bf4ba7c

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

templates/node/src/client.ts.twig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,8 @@ class Client {
240240
return response;
241241
}
242242

243-
async ping(): Promise<{ pingCount: number, pingedAt: Date }> {
244-
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {
245-
'projectId': this.config.projectId,
246-
}, 'json');
243+
async ping(): Promise<string> {
244+
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {}, 'json');
247245
}
248246

249247
async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {

templates/web/src/client.ts.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ class Client {
634634
return response;
635635
}
636636

637+
async ping(): Promise<string> {
638+
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {}, 'json');
639+
}
640+
637641
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
638642
const { uri, options } = this.prepareRequest(method, url, headers, params);
639643

tests/WebChromiumTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class WebChromiumTest extends Base
2121
'docker run --network="mockapi" --rm -v $(pwd):/app -e BROWSER=chromium -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node tests.js';
2222

2323
protected array $expectedOutput = [
24+
...Base::PING_RESPONSE,
2425
...Base::FOO_RESPONSES,
2526
...Base::BAR_RESPONSES,
2627
...Base::GENERAL_RESPONSES,

tests/WebNodeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class WebNodeTest extends Base
2222
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/web node:18-alpine node node.js';
2323

2424
protected array $expectedOutput = [
25+
...Base::PING_RESPONSE,
2526
...Base::FOO_RESPONSES,
2627
...Base::BAR_RESPONSES,
2728
...Base::GENERAL_RESPONSES,

tests/languages/web/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
document.getElementById("start").addEventListener("click", async () => {
2020
let response;
2121
let responseRealtime = 'Realtime failed!';
22+
2223
// Init SDK
2324
const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = Appwrite;
2425
const client = new Client();
@@ -27,6 +28,12 @@
2728
const bar = new Bar(client);
2829
const general = new General(client);
2930

31+
// Ping
32+
client.setProject('123456');
33+
response = await client.ping();
34+
console.log(response.result);
35+
36+
// Realtime setup
3037
client.setProject('console');
3138
client.setEndpointRealtime('ws://demo.appwrite.io/v1');
3239

tests/languages/web/node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ async function start() {
55

66
console.log('\nTest Started');
77
const client = new Client();
8+
client.setProject('123456');
89
const foo = new Foo(client);
910
const bar = new Bar(client);
1011
const general = new General(client);
12+
13+
// Ping
14+
response = await client.ping();
15+
console.log(response.result);
16+
1117
// Foo
1218
response = await foo.get('string', 123, ['string in array']);
1319
console.log(response.result);

0 commit comments

Comments
 (0)