Graceful stopping and minor fixes

This commit is contained in:
Sugui 2024-04-15 18:30:18 +02:00
parent 7a7e3bb2b3
commit 95c93012be
5 changed files with 12 additions and 7 deletions

View File

@ -28,7 +28,8 @@ services:
fe-middleware:
image: oven/bun:1
container_name: fe-middleware
command: bun run docker-dev
entrypoint: /bin/bash -c
command: ["bun --hot run src/index.ts"]
working_dir: /usr/src/app
ports:
- "8081:8081"

View File

@ -20,8 +20,7 @@
},
"scripts": {
"start": "bun run src/index.ts",
"docker-dev": "bun --hot run src/index.ts",
"dev": "docker compose down -v && docker compose up",
"test": "docker compose down -v && docker compose run fe-middleware bun test"
"test": "docker compose down -v && docker compose run fe-middleware 'sleep 5 && bun test'"
}
}

View File

@ -3,6 +3,13 @@ import app from "./app";
const PORT = env.PORT;
app.listen(PORT, () =>
const server = app.listen(PORT, () =>
console.log(`Express server listening on port ${PORT}`)
);
);
process.on("SIGTERM", (code) => {
server.close(() => {
console.log('Server closed.');
process.exit(0);
});
});

View File

@ -6,7 +6,6 @@ class BotApiService {
async getAll(): Promise<BotApiResponse> {
const get_url = `${this.BOT_API_URI}/images`;
console.log(`Connecting to "${get_url}"...`)
const response: BotApiResponse = await fetch(get_url)
.then(res => {
if (!res.ok) {

View File

@ -27,7 +27,6 @@ describe("endpoint returns the correct status codes", () => {
it("should return 500 if any error happens", async () => {
mock.module("../../src/services/ImageService", () => {
let alreadyCalled = false;
return {
default: {
get: () => {