Skip to content

Commit

Permalink
Add logging on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
Irenej Bozovicar committed Jan 8, 2024
1 parent b1b6b29 commit 9a9ad82
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion functions/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const express = require('express');
const router = express.Router();
const { db } = require('./firebase');
const { YoutubeTranscript } = require('youtube-transcript');
const {
info,
error,
} = require("firebase-functions/logger");

const collectionName = 'transcripts_test3'; // Adjust the collection name

Expand All @@ -10,12 +14,15 @@ router.get('/transcripts/search-word-in-random-video', async (req, res) => {
const searchTerm = req.query.term.toLowerCase(); // Extract search term from query parameters
const page = req.query.page || 1; // Extract page number from query parameters, default to 1
const pageSize = 100; // Set your desired page size


info(`Search term: ${searchTerm} was used for "search-word-in-random-video`);

const matchingClips = await findMatchingClipsInFirestore(searchTerm, page, pageSize);
res.json(matchingClips);

} catch (error) {
console.error(error);
error(error)
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand All @@ -24,6 +31,8 @@ router.get('/transcripts/search-word-in-random-video', async (req, res) => {
try {
const searchWord = req.query.word.toLowerCase();
const searchUrl = req.query.url;

info(`Search word: ${searchWord} was used for video with this ID:${searchUrl} `);

// Check if searchUrl is provided
if (!searchUrl) {
Expand All @@ -46,10 +55,12 @@ router.get('/transcripts/search-word-in-random-video', async (req, res) => {
res.json(responseData);
} catch (fetchError) {
console.error(fetchError);
error(fetchError);
res.status(500).json({ error: 'Error fetching transcript data' });
}
} catch (error) {
console.error(error);
error(error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand Down

0 comments on commit 9a9ad82

Please sign in to comment.