Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Docker image size, and app's close event handler. #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
CMD ["node", "server.js"]
28 changes: 19 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
@@ -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;