Socket.io does not send domain cookies

I connect to a socket from the beta.site.com subdomain, but when connecting, only cookies from the site.com and .site.com domain are sent
Why might this happen and how can I fix it?

server:

this.io = new Server(HTTPServer, {
            cors: {
                origin: process.env.SOCKET_ORIGIN,
                methods: ["GET", "POST"],
                credentials: true,
                transports: ['websocket', 'polling']
            },
            cookie: true,
            allowEIO3: true
        });

client:

socket = io(socketEndPoint, {
        withCredentials: true
    });

How to save persistent values in PHP and remove all the persistent values on tab close

I have an calendar application that does look like this:
Calendar app.

The function I am implementing is the navigation through the months (previous month/next month) function.

During the implementation I have encountered a few problems:

  1. PHP cannot easily persist variables.
  2. Persistent values have to be deleted/removed when closing the tab/opening the page for the first time.

Adressing Issues
2. There are several ways to persist a variable:

Starting a session

session_start();
$_SESSION["favcolor1"] = "green";
echo $_SESSION["favcolor1"];

Issues

  1. The value persists, but the variables are nowhere to be found in the app memory.
  2. When closing the tab, the value remains, which is a problem.

Saving as cookie

setcookie("TestCookie", "Hello World", time()+3600);
echo $_COOKIE["TestCookie"];

The variable can be found in the app storage

Issues

  1. If there is an echo before setcookie, it will be cancelled, i.e. it will not be executed. (xDD).
  2. When closing the tab, it persists, which is a problem.

Other possible solutions

  1. External files, which should work with include and `define
  2. Using a database to keep track of persistent variables.

2. Tab close event can be done via JS with beforeunload ??
Is there a way to do it via PHP ?

The problem persists:

  1. The variable should persist, which can be solved
  2. The values should be cancelled when the tab is closed.

How to set up a pagination automation?

So I’m building a website for a bakery that contains a shop page and the admin can add products to the shop page. Every time after adding a specific amount of products i want the website to create automatically a new page of products. How do i do that?

<div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <div class="shop__pagination">
                            <a href="#">1</a>
                            <a href="#">2</a>
                            <a href="#">3</a>
                            <a href="#"><span class="arrow_carrot-right"></span></a>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6">
                        <div class="shop__last__text">
                            <p>Showing 1-9 of 10 results</p>
                        </div>
                    </div>
                </div>

this is the html code that does nothing actually.

How can I prevent Vite from adding unused CSS code to the final bundle?

I was testing a UI kit I was developing as a pet project and ran into a problem. For some unknown reason, Vite adds CSS code that I do not use in the final web application bundle.
Code:
`
import { Button } from ‘kuui-react’

function App() {
    return <Button>Button</Button>
}

export default App

In the component library, I have provided the ability to import specific components from the entire library. Here is an example of importing and exporting components in the library:
import { Title as e } from “./ui/Title/Title.js”;
export {e as Title}
Here is an example of my component in the library:
import “../../assets/Title.css”;
// Component code
`
When I run: npm run build. I’m getting a CSS file with all the styles from kuui-react. How can I solve this problem?

I tried using cssCodeSplit, cssMinify and so on in Vite configuration but it didn’t solve my problem.

The data output from the compiler cannot be displayed normally in the chrome developer tool

I.m a new developer,when I output data to the console in the code editor, the output result was normal before. Now suddenly there is a lot of hot-update data in the console. It cannot become normal unless I click refresh in the upper left corner.normal abnormal

I’ve been searching for a long time but haven’t found the corresponding problem. I hope the output results can become normal.

I am trying to draw a map using d3 and I am pulling data from a json file but it’s not working. below is my script.js

let countyURL = 'https://raw.githubusercontent.com/deldersveld/topojson/master/countries/nigeria/nigeria-states.json'


let countyData

let canvas = d3.select('#canvas')
let tooltip = d3.select('#tooltip')

let drawMap = () => {
 
    canvas.selectAll('path')
            .data(countyData)
            .enter()
            .append('path')
            .attr('d', d3.geoPath())
            .attr('class', 'county')
           
}

d3.json(countyURL).then(
    (data, error) => {
        if(error){
            console.log(log)
        }else{
            //countyData = topojson.feature(data, data.objects.counties).features
            countyData = topojson.feature(data, data.objects.NGA_adm1).features
            console.log(countyData)
            drawMap()
        }
    }
)

I created a drawmap() function which I called but the map is not coming up
I don’t know if I making any mistake in my referencing (data.objects.NGA_adm1)

this is my map data source (“https://raw.githubusercontent.com/deldersveld/topojson/master/countries/nigeria/nigeria-states.json”)

Please I will really appreciate if I can get any help

Polling APIs with react and setInterval

I am trying to poll the spotify API every second with setInterval when the component is loaded in. However, when testing this I receive an error: Invalid Hook Call..etc.
I believe this is because I am using useEffect within another useEffect when I am polling. I am not sure how to overcome this.

const getCurrentSong = () => {

        useEffect(() => {
            fetch('/spotify/current-song').then((response) => {
                // check if not ok
                if(!response.ok){
                    return {};
                } else {
                    return response.json();
                }
            }).then((data) => {
                setSong(data);
                console.log(data);
            });
        },
        [])
        
    }

    getRoomdetails();
    getCurrentSong();
    
    useEffect(() => {
        const interval = setInterval(()=>{
            //getCurrentSong();
            console.log("test");
        }, 1000)

        return () => clearInterval(interval);
    }, []);

This is the part of the code that is of concern. I initially tried to get rid of the useEffect in the getCurrentSong function but this would mean that I would get stuck in a loop of that function running which is not what I want. Ideally, I want the component to render, call the API, then poll it every second for any updates.

Socketio sends old cookies

My socket connection is sending old cookies, I’m using reverse proxy. Perhaps it is cached somehow?

nginx:

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name ws.site.com;

  ssl_certificate cert.pem;
  ssl_certificate_key privkey.pem;


  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;

    proxy_pass https://123:3000;
    proxy_cache off;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

Connecting to a socket is the most common; by default it takes cookies and sends them in the header.

Immediately I see cookies that have not been on the site for a very long time. I reloaded the page to reconnect the socket, I restarted the server – nothing helps.

html page problem in the visual studio code

when i run my code in VS (macbook) it appear This site can’t be reachedlocalhost refused to connect. + http://localhost:8080/
how i can solve this problem and how to run in Firefox instead of Chrome

give me solution of this problem and how to run my code in Firefox

How to add Twitter embed to Quill js?

I have a website for a journalist that needs to embed tweets in his texts, I am currently using this code to paste the twitter blockquote in the text but it does not seems to work, I guess its something related to quill removing the class=”twitter-tweet” when displaying it on the editor, (I already enabled access to Twitter requests in the cookies and using dangerously paste HTML should not be a problem i guess, since the only user is the owner of the website). Any help would be of great value 🙂

the relevant part of my script:

  <script>
            document.cookie = "cookieName=cookieValue; SameSite=None; Secure";
            let delta;
            var quill = new Quill('#editor', {
                theme: 'snow',
                sanitize: false,
                modules: {
                    toolbar: [
                        ['bold', 'italic', 'underline', 'image', 'video'],
                        [{ size: ['small', false, 'large', 'huge'] }]
                    ]
                },
                attributes: {
                    blockquote: ''
                },
                formats: {
                    image: 'image-size-limited' // Apply custom CSS class to images
                }
            });

            const twitterHtml = document.getElementById('twitterHtml');
            const addTweetButton = document.getElementById('addTweetButton');
            addTweetButton.addEventListener('click', function (event) {
                event.preventDefault();
                const tweet = twitterHtml.value;

                // Extract the non-script portion of the tweet HTML
                const tweetWithoutScripts = tweet.replace(/<script.*?>[sS]*?</script>/g, '');

                // Append the non-script portion to the Quill editor
                quill.clipboard.dangerouslyPasteHTML(tweetWithoutScripts);

                // Add the Twitter widget script to your document
                const twitterScript = document.createElement('script');
                twitterScript.src = 'https://platform.twitter.com/widgets.js';
                twitterScript.charset = 'utf-8';
                twitterScript.async = true;

                // Handle script onload or other event if needed
                twitterScript.onload = function () {
                    // The Twitter script has loaded, you can perform additional actions if required
                };

                // Append the Twitter script to the document
                document.body.appendChild(twitterScript);

                twitterHtml.value = '';
            });

what shows up in the editor
what shows up in the inspector

How to design the following custom UI headline with ReactJS, CSS and bootstrap?

I want to develop the following type of design in a responsive in ReactJS using Bootstrap or CSS(if necessary). This is not a header. How should I put the separators between each column and make the values of each label in the next line in the same column using Bootstrap or CSS Flexbox?
I need to have it equally spaced and should be responsive in a way when I resize the browser window it should not overflow. All the items are left aligned in each column.

Sandbox Code –

Edit runtime-sunset-2t7yyz

The UI Design –
Design

how to solve node js warning-(node:3384) MaxListenersExceededWarning: Possible EventEmitter memory leak detected

(node:3384) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connected listeners added to [NativeConnection]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)

I got this problem with my node js project and I searched for solution in internet most of them suggest to use setMaxlisteners() to increase limit ,I used that also but my issue was not solved so can anyone help me to solve this

I got this problem with my node js project and I searched for solution in internet most of them suggest to use setMaxlisteners() to increase limit ,I used that also but my issue was not solved so can anyone help me to solve this

Navbar active links using JavaScript and Bootstrap

I’m pretty new to everything, especially JavaScript.
I have a navbar and when I click on one of the links it should have the class active and also change colour, to show everyone who browses the page, where they are, pretty normal and typical website navigation stuff. My navbar is also loaded on every page with JavaScript and jQuery, maybe that is an issue here.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>navbar</title>

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
    <link rel="stylesheet" href="css/stylesheet.css" />
    <script src="https://code.jquery.com/jquery-3.6.3.js"
        integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM=" crossorigin="anonymous"></script>
</head>

<body>

    <nav class="navbar fixed-top navbar-expand-sm navbar-dark shadow p-3 mb-5 rounded">
        <div class="container">
            <a href="./index.html" class="navbar-brand mb-0 h1" style="font-size: x-large; color: cornsilk">guapo.
                <img class="d-inline-block align-top" src="images/clementine.png" width="38" height="38" />
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span><i id="menu-icon" class="bi bi-list"></i></span>
            </button>
            <div class="collapse navbar-collapse justify-content-between" id="navbarNav" style="color: cornsilk">
                <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a href="gefilterte-produkte.html?category=pflanzen" class="nav-link active"
                            id="pflanzen">Pflanzen</a>
                    </li>
                    <li class="nav-item">
                        <a href="gefilterte-produkte.html?category=toepfe" class="nav-link" id="toepfe">Töpfe</a>
                    </li>
                    <li class="nav-item">
                        <a href="gefilterte-produkte.html?category=pflanzenfreunde" class="nav-link"
                            id="pflanzenfreunde">Pflanzenfreunde</a>
                    </li>
                </ul>
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item me-3">
                        <a href="login.html" class="navbar-link">
                            <i class="bi bi-person-fill"></i>
                        </a>
                    </li>
                    <li class="nav-item me-3">
                        <a href="einkaufswagen.html" class="navbar-link">
                            <i class="bi bi-cart2"></i>
                        </a>
                    </li>
                </ul>
            </div>

        </div>
    </nav>
</body>

</html>

this is my html for the navbar.

$("#navbar").load("../Frontend/navbar.html .navbar");

this is how my navbar is loaded on every page.

I have tried a lot of JavaScript codes but nothing seems to be working, I just cannot figure it out.