From 2ee40fba3342daebad9b618c6661e0c583b439f6 Mon Sep 17 00:00:00 2001 From: Baraa Al-Masri Date: Thu, 9 May 2024 20:25:10 +0300 Subject: [PATCH 1/2] Replace debian image with alpine --- Dockerfile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7fd0b02..328ad00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,9 @@ -FROM node:14.15.0 +FROM node:18-alpine -WORKDIR /usr/src/app - -COPY package*.json ./ - -RUN npm install +WORKDIR /app COPY . . +RUN npm install EXPOSE 8080 - -CMD [ "node", "server.js" ] \ No newline at end of file +CMD ["node", "server.js"] From d67742b59ce2322001674275254f0c85b38a488d Mon Sep 17 00:00:00 2001 From: Baraa Al-Masri Date: Thu, 9 May 2024 20:25:32 +0300 Subject: [PATCH 2/2] Add close events handlers --- server.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 5682bff..574796e 100644 --- a/server.js +++ b/server.js @@ -1,21 +1,31 @@ -const express = require('express'); -const scraper = require('./scraper') +const express = require("express"); +const scraper = require("./scraper"); const app = express(); +const process = require("process"); + +function stop() { + console.log("gracefully shutting down the server..."); + process.exit(); +} + +process.on("SIGINT", stop); // Ctrl+C +process.on("SIGTERM", stop); // docker stop //Home page -app.get('/', (req, res) => { - res.sendFile(__dirname + "/index.html"); +app.get("/", (req, res) => { + res.sendFile(__dirname + "/index.html"); }); //API route -app.get('/api/search', (req, res) => { - scraper.youtube(req.query.q, req.query.key, req.query.pageToken) - .then(x => res.json(x)) - .catch(e => res.send(e)); +app.get("/api/search", (req, res) => { + scraper + .youtube(req.query.q, req.query.key, req.query.pageToken) + .then((x) => res.json(x)) + .catch((e) => res.send(e)); }); app.listen(process.env.PORT || 8080, function () { - console.log('Listening on port 8080'); + console.log("Listening on port 8080"); }); module.exports = app;