Skip to content

Commit

Permalink
✨ Add support for expected status codes (fixed com/upptime/upptime#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 19, 2020
1 parent 3aa657f commit 010d02c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface UpptimeConfig {
method?: string;
name: string;
url: string;
expectedStatusCodes?: number[];
assignees?: string[];
headers?: string[];
__dangerous__insecure?: boolean;
Expand Down
27 changes: 26 additions & 1 deletion src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,32 @@ export const update = async (shouldCommit = false) => {
const result = await curl(site);
console.log("Result", result);
const responseTime = (result.totalTime * 1000).toFixed(0);
const status: "up" | "down" = result.httpCode >= 400 || result.httpCode < 200 ? "down" : "up";
const expectedStatusCodes = (
site.expectedStatusCodes || [
200,
201,
202,
203,
200,
204,
205,
206,
207,
208,
226,
300,
301,
302,
303,
304,
305,
306,
307,
308,
]
).map(Number);
console.log("Expected status codes", expectedStatusCodes);
const status: "up" | "down" = expectedStatusCodes.includes(result.httpCode) ? "down" : "up";
return { result, responseTime, status };
};

Expand Down

0 comments on commit 010d02c

Please sign in to comment.