Skip to content

Update/netlify functions#73

Open
yaacovkdev wants to merge 54 commits intodevelopfrom
update/netlify-functions
Open

Update/netlify functions#73
yaacovkdev wants to merge 54 commits intodevelopfrom
update/netlify-functions

Conversation

@yaacovkdev
Copy link
Collaborator

@yaacovkdev yaacovkdev commented Sep 30, 2025

added new route for server that would check airtable database for status of the promptID generated data.
the client now asks the server for several intervals for the data of generated recipes until the time runs out or it gets an answer.
server will ask for firestore json if airtable item will tell it that the n8n workflow has generated the recipe.
Server is set to work with n8n workflow 2.0

This update is for ability of the server api to be able to run on short lived serverless functions, like netlify functions.

yaacovkdev and others added 30 commits April 19, 2025 01:29
verify if server user preferences are passed down successfully
# Conflicts:
#	server/controllers/recipesController.js
@nicmart-dev
Copy link
Owner

nicmart-dev commented Sep 30, 2025

Can you please create a design document (eg. In a docs folder) that also describes how this change fits in the big picture? Cursor AI or Copilot is great for this

Copy link
Owner

@nicmart-dev nicmart-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements! I spotted a few blockers, using Cursor Agents:

1. server/controllers/databaseController.js: keep the Firebase service account out of git

const feedmenowAccount = (() => {
    const raw = process.env.FEEDMENOW_RECIPES_SERVICE_ACCOUNT;
    if (!raw) {
        throw new Error('FEEDMENOW_RECIPES_SERVICE_ACCOUNT env var is required');
    }
    const parsed = JSON.parse(raw);
    parsed.private_key = parsed.private_key?.replace(/\\n/g, '\n');
    return parsed;
})();

2. server/controllers/databaseController.js: avoid double-initializing Firebase apps

        feedmenowAccount.private_key_id = process.env.FEEDMENOW_RECIPES_KEY_ID;
        feedmenowAccount.private_key = process.env.FEEDMENOW_RECIPES_KEY?.replace(/\\n/g, '\n');

        const feedmenowRecipesApp =
            admin.apps.find((app) => app.name === 'FeedMeNowRecipes') ??
            admin.initializeApp({ credential: cert(feedmenowAccount) }, 'FeedMeNowRecipes');

3. server/controllers/recipesController.js: guard when Airtable returns no records so polling clients don’t crash

        const record = responseAirtable.data.records?.[0];
        if (!record) {
            return res.status(404).json({ error: 'Recipe request not found.' });
        }

        if(record.fields.status == "Success") {
            const firestoreID = record.fields.firestoreID.slice(0, -1);

4. client/src/pages/Home/Home.jsx: default the cached recipes to an empty array

                            const existingRecipes = JSON.parse(localStorage.getItem('recipes') ?? '[]');
                            existingRecipes.unshift({prompt: responseReady.data.prompt, dishes: responseReady.data.dishes});

5. client/src/pages/RecipeSuggestions.jsx: register the document click handler inside useEffect with cleanup

    const mouseClickFunction = (promptitem) => {
        if(document.querySelector(`#nav-${promptitem}`)) {
            document.querySelector(`#nav-${promptitem}`).classList.add("hidden");
        }
        setShowPromptMenu(-1);
    };

    useEffect(() => {
        const handleDocumentClick = () => mouseClickFunction(showPromptMenu);
        document.addEventListener("click", handleDocumentClick);
        return () => document.removeEventListener("click", handleDocumentClick);
    }, [showPromptMenu]);

Addressing these keeps secrets out of git, prevents Firebase init errors, and makes the polling flow resilient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants