Connected healthcheck with health function to check client status, and switched to Pnpm

This commit is contained in:
Simon Hyll
2023-02-05 17:11:55 +01:00
parent b526da2e3a
commit cfaee7cfa8
7 changed files with 1536 additions and 1372 deletions

View File

@@ -50,7 +50,7 @@ All contributions are welcome, please try and make an issue first since most new
cp .env.example .env
```
2. Run the bot with `yarn dev`
2. Run the bot with `pnpm dev`
### Code Conventions
@@ -61,5 +61,5 @@ Since there is no user facing code, prefer `snake_case` for variables and functi
The bot uses the [tsm](https://github.com/lukeed/tsm) module loader to transpile its Typescript code on the fly so there's no build step involved.
```sh
yarn start
pnpm start
```

26
healthcheck.yaml Normal file
View File

@@ -0,0 +1,26 @@
envs:
- key: DISCORD_TOKEN
scope: RUN_AND_BUILD_TIME
type: SECRET
value: ******
- key: NODE_ENV
scope: RUN_AND_BUILD_TIME
value: production
name: tauri-discord-bot
region: lon
services:
- environment_slug: node-js
github:
branch: main
deploy_on_push: true
repo: tauri-apps/tauri-discord-bot
health_check:
http_path: /api/v1/health
http_port: 3000
instance_count: 1
instance_size_slug: basic-xxs
name: tauri-discord-bot
routes:
- path: /
source_dir: /

1483
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,17 +4,24 @@ import http from 'http';
const app = express();
const router = express.Router();
router.use((req, res, next) => {
router.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
res.header('Access-Control-Allow-Methods', 'GET');
next();
const status = app.locals.getStatus()
if (status === 200) {
next();
} else {
res.status(status).send({ error: 'Something failed!' })
}
});
router.get('/health', (req, res) => {
res.status(200).send('Ok');
router.get('/health', (req: express.Request, res: express.Response) => {
res.status(200).send('Ok');
});
app.use('/api/v1', router);
const server = http.createServer(app);
export default server.listen(3000);
export default function (callback: any) {
app.locals.getStatus = callback
const server = http.createServer(app);
return server.listen(3000);
}

View File

@@ -31,7 +31,13 @@ const client = new JellyCommands({
cache: DEV_MODE,
});
// Auto reads the DISCORD_TOKEN environment variable
client.login();
function health() {
if (!client.isReady())
return 502
return 200
}
healthcheck;
healthcheck(health);
// Auto reads the DISCORD_TOKEN environment variable
await client.login()

View File

@@ -1,8 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "Node16",
"esModuleInterop": true,
"target": "es6",
"target": "ES2022",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,

1358
yarn.lock

File diff suppressed because it is too large Load Diff