Merge pull request #137 from Code42Cate/health-checks
Add basic health check api route
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "plunk",
|
"name": "plunk",
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "agpl-3.0",
|
"license": "agpl-3.0",
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { Webhooks } from "./controllers/Webhooks";
|
|||||||
import { V1 } from "./controllers/v1";
|
import { V1 } from "./controllers/v1";
|
||||||
import { prisma } from "./database/prisma";
|
import { prisma } from "./database/prisma";
|
||||||
import { HttpException } from "./exceptions";
|
import { HttpException } from "./exceptions";
|
||||||
|
import { Health } from "./controllers/Health";
|
||||||
|
|
||||||
const server = new (class extends Server {
|
const server = new (class extends Server {
|
||||||
public constructor() {
|
public constructor() {
|
||||||
@@ -69,6 +70,7 @@ const server = new (class extends Server {
|
|||||||
new Identities(),
|
new Identities(),
|
||||||
new Tasks(),
|
new Tasks(),
|
||||||
new V1(),
|
new V1(),
|
||||||
|
new Health(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.app.use("*", () => {
|
this.app.use("*", () => {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Controller, Get } from "@overnightjs/core";
|
||||||
|
import type { Request, Response } from "express";
|
||||||
|
|
||||||
|
@Controller("health")
|
||||||
|
export class Health {
|
||||||
|
@Get("")
|
||||||
|
public async health(req: Request, res: Response) {
|
||||||
|
return res.json({ success: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
|
||||||
|
import { network } from './../../lib/network'
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse,
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const timeoutPromise = new Promise((_, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
reject(new Error('Timeout'));
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
const healthPromise = network.fetch("GET", "/health");
|
||||||
|
|
||||||
|
await Promise.race([healthPromise, timeoutPromise]);
|
||||||
|
|
||||||
|
return res.status(200).json({ message: 'OK' });
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(500).json({ message: 'Internal Server Error' });
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user