Add simple /ping endpoint instead of /index.json, change default fetch timeout to 30s (#1017)

pull/1027/head
Justyn Shull 2024-08-03 23:24:38 -07:00 committed by GitHub
parent ea6e4ce079
commit 4af100b7b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import type { SpacePrimitives } from "./space_primitives.ts";
import type { FileMeta } from "../../plug-api/types.ts";
import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts";
const fetchTimeout = 5000;
const defaultFetchTimeout = 30000; // 30 seconds
export class HttpSpacePrimitives implements SpacePrimitives {
constructor(
@ -15,6 +15,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
public async authenticatedFetch(
url: string,
options: RequestInit,
fetchTimeout: number = defaultFetchTimeout,
): Promise<Response> {
if (!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
// If not: throws an error or invokes a redirect
async ping() {
await this.authenticatedFetch(`${this.url}/index.json`, {
await this.authenticatedFetch(`${this.url}/.ping`, {
method: "GET",
headers: {
Accept: "application/json",
},
});
}, 5000);
}
}

View File

@ -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
this.app.post("/.rpc/shell", async (c) => {
const req = c.req;