Newer
Older
My-Portfolio / backend / routes / intro.js
const express = require('express');
const router = express.Router();
const pool = require("../db");
require("dotenv").config();


const BASE_URL = process.env.BASE_URL;

router.get("/intro", async (req, res) => {
    try {
        // Queries
        const socials = `
        SELECT name, url, logo 
        FROM social_media 
        WHERE name IN ('linkedin', 'gitbucket', 'instagram', 'facebook');
      `;

        // Perform queries correctly
        const socialsRaw = await pool.query(socials);

        // Log the entire result to see the structure
        //console.log("Socials Raw Result:", socialsRaw);

        // If rows exist, proceed with mapping
        const updatedSocials = socialsRaw?.map(social => ({
            ...social,
            logo: social.logo ? BASE_URL + social.logo : null // Handle null or undefined logo
        })) || [];

        // Combine all skills
        const intro = {
            socials: updatedSocials,
        };
        //console.log("Final intro Before Sending:", intro);

        // Send response
        res.json(intro);

    } catch (err) {
        console.error("Error fetching intro:", err.message);
        res.status(500).send("Server error");
    }
});



module.exports = router;