mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import express from 'express';
|
|
import Logger from './loaders/logger';
|
|
import config from './config';
|
|
import { HealthClient } from './protos/health';
|
|
import { credentials } from '@grpc/grpc-js';
|
|
|
|
const app = express();
|
|
const client = new HealthClient(
|
|
`0.0.0.0:${config.cronPort}`,
|
|
credentials.createInsecure(),
|
|
{ 'grpc.enable_http_proxy': 0 },
|
|
);
|
|
|
|
app.get('/api/health', (req, res) => {
|
|
client.check({ service: 'cron' }, (err, response) => {
|
|
if (err) {
|
|
return res.status(200).send({ code: 500, error: err });
|
|
}
|
|
return res.status(200).send({ code: 200, data: response });
|
|
});
|
|
});
|
|
|
|
app
|
|
.listen(config.publicPort, '0.0.0.0', async () => {
|
|
await require('./loaders/sentry').default({ expressApp: app });
|
|
await require('./loaders/db').default();
|
|
|
|
Logger.debug(`✌️ 公共服务启动成功!`);
|
|
console.debug(`✌️ 公共服务启动成功!`);
|
|
process.send?.('ready');
|
|
})
|
|
.on('error', (err) => {
|
|
Logger.error(err);
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|