mirror of
https://github.com/tauri-apps/tauri-discord-bot.git
synced 2026-01-31 00:35:21 +01:00
Connected healthcheck with health function to check client status, and switched to Pnpm
This commit is contained in:
@@ -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
26
healthcheck.yaml
Normal 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
1483
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
|
||||
12
src/index.ts
12
src/index.ts
@@ -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()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"module": "Node16",
|
||||
"esModuleInterop": true,
|
||||
"target": "es6",
|
||||
"target": "ES2022",
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
|
||||
Reference in New Issue
Block a user