Skip to content

Commit

Permalink
health check api
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo committed Oct 10, 2024
1 parent 1ea57d9 commit da09cf0
Show file tree
Hide file tree
Showing 3 changed files with 537 additions and 9 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/yargs": "^17.0.33",
"dotenv": "^16.4.5",
"eslint": "^8.8.0",
"express": "^4.21.1",
"postgraphile": "^5.0.0-beta.28",
"yargs": "latest"
},
Expand All @@ -33,6 +34,7 @@
"@apollo/client": "3.0.0",
"@geut/chan": "^3.2.9",
"@tsconfig/node20": "^20.1.4",
"@types/express": "^4",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^5",
"@typescript-eslint/parser": "5",
Expand Down
19 changes: 16 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
// SPDX-License-Identifier: GPL-3.0

import { createServer } from 'node:http';
import express from 'express';
import { grafserv } from 'grafserv/express/v4';
import { postgraphile } from 'postgraphile';
import { grafserv } from 'postgraphile/grafserv/node';
// import { grafserv } from 'postgraphile/grafserv/node';
import { genPreset, ArgsInterface } from './config/index';

export function startServer(args: ArgsInterface) {
const preset = genPreset(args);
const pgl = postgraphile(preset);
const serv = pgl.createServ(grafserv);

const server = createServer();
const app = express();
app.use((req, res, next) => {
console.log(req.url);
if (req.url === '/.well-known/apollo/server-health') {
res.setHeader('Content-Type', 'application/health+json');
res.end('{"status":"pass"}');
return;
}
next();
});
const server = createServer(app);

server.on('error', (e) => {
console.error(e);
});

serv.addTo(server).catch((e) => {
serv.addTo(app, server).catch((e) => {
console.error(e);
process.exit(1);
});
Expand Down
Loading

0 comments on commit da09cf0

Please sign in to comment.