Add simple /ping endpoint instead of /index.json, change default fetch timeout to 30s (#1017)
parent
ea6e4ce079
commit
4af100b7b7
|
@ -2,7 +2,7 @@ import type { SpacePrimitives } from "./space_primitives.ts";
|
||||||
import type { FileMeta } from "../../plug-api/types.ts";
|
import type { FileMeta } from "../../plug-api/types.ts";
|
||||||
import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts";
|
import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts";
|
||||||
|
|
||||||
const fetchTimeout = 5000;
|
const defaultFetchTimeout = 30000; // 30 seconds
|
||||||
|
|
||||||
export class HttpSpacePrimitives implements SpacePrimitives {
|
export class HttpSpacePrimitives implements SpacePrimitives {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -15,6 +15,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||||
public async authenticatedFetch(
|
public async authenticatedFetch(
|
||||||
url: string,
|
url: string,
|
||||||
options: RequestInit,
|
options: RequestInit,
|
||||||
|
fetchTimeout: number = defaultFetchTimeout,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
if (!options.headers) {
|
if (!options.headers) {
|
||||||
options.headers = {};
|
options.headers = {};
|
||||||
|
@ -199,11 +200,11 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||||
// Used to check if the server is reachable and the user is authenticated
|
// Used to check if the server is reachable and the user is authenticated
|
||||||
// If not: throws an error or invokes a redirect
|
// If not: throws an error or invokes a redirect
|
||||||
async ping() {
|
async ping() {
|
||||||
await this.authenticatedFetch(`${this.url}/index.json`, {
|
await this.authenticatedFetch(`${this.url}/.ping`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
});
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,6 +497,13 @@ export class HttpServer {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Simple ping health endpoint
|
||||||
|
this.app.get("/.ping", (c) => {
|
||||||
|
return c.text("OK", 200, {
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// RPC shell
|
// RPC shell
|
||||||
this.app.post("/.rpc/shell", async (c) => {
|
this.app.post("/.rpc/shell", async (c) => {
|
||||||
const req = c.req;
|
const req = c.req;
|
||||||
|
|
Loading…
Reference in New Issue