Router.push or Link not rendering/refreshing the page even thought the url is updated nextjs

I apologize for my horrendous way of explaining my issue. I have shared a link below description which is exactly the same issue I am experiencing. Any kind of help would be greatly appreciated.

I have directory path like pages/request/[reqid].js . When my url is localhost:3000/xyz and I navigate to pages/request/1 by clicking a button on the current page, the page successfully loads the page with proper data from [reqid=1] but when I try to access pages/request/[reqid].js with different reqid (say suppose reqid=2), the url reflects the correct the reqid pages/request/2 but the page remains the same, doesn’t change. However if I go back to other pages like localhost:3000/xyz and click a button there to navigate to pages/request/2 it works but from within pages/request/[reqid] it doesn’t render a page associated to the corresponding reqid even thought the url is updated. I have tried both Link and router.push ,both fails to render the correct reqid page.

https://github.com/vercel/next.js/issues/26270

Cloudfront with Websocket connection

I have been reading over the documentation here on connection a websocket service with a client through a cloudfront distribution but I am unable to understand where the upgrade to the websocket protocol will occur. Will the upgrade need to be handled by the server or will the cloudfront distribution handle changing the protocol to wss and respond with the connection?

How to send an embed with discord.js

I was wondering how to write an embed in discord.js. This is my current code: it is not functional. I get the warning: ‘message is not defined’ on message.channel.send I do not know how to fix this. I was hoping you guys could tell me how to fix this. js

// Embeding the image in An Embeded message
    const EmbededTweet = new MessageEmbed()
        .setColor('0x00FF00')
        .setTitle(`You made ${account} tweet this:`)
        .setImage(imageUrl)
        .setTimestamp();

    // replying with the Embeded message
    await interaction.reply({embeds: [EmbededTweet]});

Filepond revert method for delete does not send unique file id

I am trying to intergrate File Pond with my Flask server and I can not find the unique file id it sends with requests. With normal uploads it will show me request data on the server, but without the unique ID I am looking for. I want to use this unique ID to attach to a database in order to delete the file if the revert is sent later.

Going over the docs, it is suppsoed to send a unique ID with every upload, but I can’t tell if it’s a bad config in file pond or I suck at reading request.files. Just ignore all my prints where I try to read the contents of request.

Here is my FilePond Config:

    FilePond.setOptions({
        //allowImageEdit: true,
        //allowImageCrop: true,
        //allowMultiple: true,
        //allowFileEncode: true,
        allowImageExifOrientation: true,
        credits: false,
        server: {
            process: {
                url: './pondupload',
                method: 'POST',
                headers: {
                    'x-customheader': 'Hello World',
                },
                withCredentials: document.getElementById('csrf_token'),
                onload: (response) => response.key,
                onerror: (response) => response.data,
                ondata: (formData) => {
                    formData.append('csrf_token', document.getElementById('csrf_token').value)
                    return formData;
                },
            },
            revert: './pondupload',
            restore: './restore/',
            load: './load/',
            fetch: './fetch/',
        },
    });

Here is my route in flask:

@bp.route('/pondupload', methods=['POST', 'DELETE'])
def pondupload():
    print ('data: '+str(request.data))
    print('form: '+str(request.form))
    print('files: '+str(request.files))
    print('args: '+str(request.args))
    form=EmptyForm()
    #TODO add csrf to revert
    if request.method == "DELETE":
        print('delete stuff')
    if request.method == "POST" and form.validate_on_submit():
        upload_dir = current_app.config['UPLOAD_FOLDER']
        fn = ""
        file_names = []
        # get file object from request.files (see: http://flask.pocoo.org/docs/1.0/api/#flask.Request.files)
        for key in request.files:
            print('key: '+str(key))
            file = request.files[key]
            fn = secure_filename(file.filename)
            if allowed_file(fn) == True:
                file_names.append(fn)
                try:
                    file.save(os.path.join(upload_dir, fn))
                    return jsonify({}), 200
                except:
                    return jsonify(filename=file_names), 402
    return jsonify({}), 400

react js rendering blank [age with no errors on console

So basically I have a navbar that switches between routes. When the page loads, it goes to my localhost by default but doesn’t actually render the App component it’s being given. I believe the problem is within the navbar as the app renders other components when the Nav component is not included. Please assist me if you can.

code to the questions is given below:
app.js

    import React from 'react';
import './App.css';
import Nav from './components/Navbar/navbar';
import Content from './components/Header/firstsec';
import Grid from './components/secondsec/secondsec';
import Footer from './components/footer/footer';
import Sign from './components/signin/signin';
import Trend from './components/trending/trending';


function App() {
  return (   
      <div>
       <Nav/>
     <Content />    
     <Grid />
     <Footer />
     <Sign />
     <Trend />
     </div>
     
     
  );
}

export default App;

navbar.js

    import React from "react";
import {
  BrowserRouter as Router,
  Route,
  Routes,
  Link} from "react-router-dom";
import Content from "../Header/firstsec";
import Grid from "../secondsec/secondsec";
import Trend from "../trending/trending";
import Sign from "../signin/signin";
import { Component } from "react/cjs/react.development";



export default class Nav extends Component{
  render(){
    return (
    <Router>
    <div>
      <nav className="bg-gradient-to-r from-blue-300 to to-purple-500 via-black">
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-6">
          <div className="flex items-center justify-between h-36">
            <div className="flex items-center">
              <div className="flex-shrink-0">
                <img
                  className="h-8 w-8"
                  src="https://tailwindui.com/img/logos/workflow-mark-indigo-500.svg"
                  alt="Workflow"
                />
              </div>
              <div className="hidden md:block">
                <div className="ml-10 flex items-baseline space-x-4">
                  <Nav.Link as={Link} to ={"/"}
                    
                    className=" hover:bg-gray-700 text-white px-3 py-2 rounded-md text-sm font-medium"
                  >
                    Bloow
                  </Nav.Link>
                  <Nav.Link as={Link} to ={"/Content"}
                    className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium">
                    Bloow TV
                  </Nav.Link>

                  <Nav.Link as={Link} to ={"/Grid"}
                    className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
                  >
                    Bloow Music
                  </Nav.Link>

                  <Nav.Link as={Link} to ={"/Trending"}
                    className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
                  >
                    Trending
                  </Nav.Link>
                  <div>
                  <Nav.Link as={Link} to ={"/Sign"}
                    className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
                  >
                    Sign in
                  </Nav.Link>

                 

                  </div>      
              </div>
            </div>
            <div className="-mr-2 flex md:hidden">
              <button
                type="button"
                className="bg-gray-800 inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white"
                aria-controls="mobile-menu"
                aria-expanded="false"
              >
                <span className="sr-only">Open main menu</span>

                <svg
                  className="block h-6 w-6"
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke="currentColor"
                  aria-hidden="true"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                    d="M4 6h16M4 12h16M4 18h16"
                  />
                </svg>

                <svg
                  className="hidden h-6 w-6"
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke="currentColor"
                  aria-hidden="true"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                    d="M6 18L18 6M6 6l12 12"
                  />
                </svg>
              </button>
            </div>
          </div>
        </div>
        </div>

        <div className="md:hidden" id="mobile-menu">
          <div className="px-2 pt-2 pb-3 space-y-1 sm:px-3">
            <Nav.Link as={Link} to ={"/home"}
              className="hover:bg-gray-700 text-white block px-3 py-2 rounded-md font-medium text-5xl"
            >
              Bloow
            </Nav.Link>

            <Nav.Link as={Link} to ={"/Content"}
              
              className="text-gray-300 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
            >
              Bloow TV
            </Nav.Link>

            <Nav.Link as={Link} to ={"/Grid"}
              className="text-gray-300 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
            >
              Bloow Music
            </Nav.Link>

            <Nav.Link as={Link} to ={"/Trending"}
              className="text-gray-300 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
            >
              Trending
            </Nav.Link>

            <Nav.Link as={Link} to ={"/Sign"}
              className="text-gray-300 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
            >
              Sign in
            </Nav.Link>
          </div>
        </div>
      </nav>
    </div>
    <div>
      <Routes>
        <Route path="/" Component ={Content} />
        <Route path="/Content" Component ={Content}>
        </Route>
        <Route path="/Grid" Component ={Grid}>
          <Grid />
        </Route>
        <Route path="/Trending" Component={Trend}>
          <Trend />
        </Route>
        <Route path="/Sign" Component={Sign}>
          <Sign />
        </Route>
      </Routes>
      
    </div>
    </Router>
  );

}
}

    

Heroku Cannot Get/ when getting data from MongoDB through Heroku API Using MEN Stack

js express server and Heroku API hosting.

I created a backend that allows me to post and get data from MongoDB through express server that is hosted on Heroku , I’m using postman for testing.

POST method works well both locally and on Heroku.
GET method only works locally and I get A Cannot GET / error with a 404 code when I test on Heroku.

This is my code below:

router.get('/posts', async (req, res) => {
    try {
        const posts = await Posts.find();
        res.json(posts)
        console.log('data',res.send)
    }catch (err) {
        res.send('error', err)
    }
});

module.exports = router;

Fetching products from more bases(axios, nodejs)

This is my codeHello guys. I have a project that I have to finish in 3 days. My problem is when adding products to the cart, I have to fetch products from three different bases, while I only do fetching products from one base. How can I do that, please help. My code: const {data} = await axios.get(‘/api/products/${id}’); And this works but just from this base, i was trying const {data} = await axios.get(‘/api/products/${id}’ || ‘/api/felnes/${id}’ || ‘/api/primes/${id}’); but this doesn’t worked. to mention the variable must only be {data}, because otherwise I get an error id is undefined. I’m new in react.

Cropping the relevant part of the browser window after identifying the location of the interested element

I have a webpage where I’ve embedded a YouTube video in an iframe. I need to capture the screenshot of the YouTube video. Using libraries like html2canvas and dom2image didn’t work because of cross-domain limitations.

So, I came up with the idea of capturing the screenshot of the full browser window using getDisplayMedia() and then cropping the relevant part using drawImage(). In my head, it seems to make complete sense, just identifying the location of the iframe and then using drawImage to crop it. However, it does not crop the relevant part in all screen sizes. When I change screen resolution or zoom in, it seems to break.

Another idea would be to write an AI algorithm to capture this. But I think that is an overkill. Any ideas on how to make it work for all screen sizes and resolutions?

<h1>Hello</h1>
<div style="margin: 10;">
    <iframe 
        id="youtubeiframe" 
        width="640" 
        height="340" 
        src="https://www.youtube.com/embed/vDYP6AKw8bk?controls=0" 
        title="YouTube video player" frameborder="0" 
        allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen>
    </iframe>
</div>
<div id="picture" style="margin-top:60; background-color:'gray'"></div> 

<script>
        navigator.mediaDevices.getDisplayMedia({ preferCurrentTab: true }).then(stream => {
        captureStream = stream;
        track = captureStream.getVideoTracks()[0];
        const canvas = document.createElement("canvas");
        const context = canvas.getContext("2d");
        const offsets = document.getElementById("youtubeiframe")?.getBoundingClientRect();
        const posX = offsets.left;
        const posY = offsets.top;
        const width = offsets.width;
        const height = offsets.height;
        canvas.width = width;
        canvas.height = height;

        let image = new ImageCapture(track);
        const bitmap = image.grabFrame().then(bitmap => {
            context?.drawImage(bitmap, posX, posY, width, height, 0, 0, width, height);
            const pic = document.getElementById("picture");
            if(pic.childElementCount > 0)
                pic.replaceChild(canvas,pic.children[0]);
            else
                pic.appendChild(canvas);
        });
        
    });
    
</script>

how to remove an array item from firestore using JavaScript?

I’m trying to add a delete button to my page. the event listener callback is working properly except for the updateDoc function.

await updateDoc(doc(dataBase, 'users', `${auth.currentUser.uid}`), {
     [`${col}.books`]: arrayRemove(`${bookToDelete}`)
}).then(()=>{
      // fulfilled
      console.log('book deleted')
      }, ()=>{
      // rejected
      console.log('promis rejected')
})   

Col is the object that contains the books array. In the console it always prints book deleted, but in the firestore console, nothing changes. this is a screenshot of the database.enter image description here

I would really appreciate any help and thank you.

Using Place Autocomplete API to get Address Components

I am trying to to have a form that uses the Google Autocomplete API to populate a bunch of text fields after they click the name of the establishment. I am not super familiar with Javascript, so this one is somewhat of a struggle for me.

As is, I am currently getting it to populate the Name into the input box and the latitude and longitude. But everything else (address, address2, city, state) gets populated with “undefined”. Any ideas on how to get those values to populate into those input fields.

<html>
<head>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API&libraries=places"></script>
    <script>
        function initialize() {
          var input = document.getElementById('searchTextField');
          const options = {
          componentRestrictions: { country: "us" },
          fields: ["address_components", "geometry", "icon", "name"],
          strictBounds: false,
          types: ["establishment"],
          };
          var autocomplete = new google.maps.places.Autocomplete(input, options);
            google.maps.event.addListener(autocomplete, 'place_changed', function () {
                var place = autocomplete.getPlace();
                document.getElementById('locationName').value = place.name;
                document.getElementById('addr').value = place.adr_address;
                document.getElementById('addr2').value = place.address2;
                document.getElementById('city').value = place.city;
                document.getElementById('state').value = place.state;
                document.getElementById('lat').value = place.geometry.location.lat();
                document.getElementById('long').value = place.geometry.location.lng();
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>
<body>
    <input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on" runat="server" />

    <input type="text" id="locationName" name="locationName" />
    <input type="text" id="addr" name="addr" />
    <input type="text" id="addr2" name="addr2" />
    <input type="text" id="city" name="city" />
    <input type="text" id="state" name="state" />
    <input type="hidden" id="lat" name="lat" />
    <input type="hidden" id="long" name="long" />

</body>
</html>

React play different audio files at once – working with different refs

I’m creating a small app that plays an audio file and have some functionalities (loop, stop, mute). My goal is to add some more audio files that all should be played and stopped at once (one button to control all), but each will have a mute button, and I’m not sure what is the best practice to do so. I used useRef and thought maybe I need to set a refs array but how will I be able to start/stop them all at once, but still have the ability to control the mute separately?

This is my code so far. I guess I should split and have a different component for the audio sounds. Thanks for helping!

import React, {useState, useRef, useEffect} from 'react'
import {ImPlay2} from "react-icons/im"
import {ImStop} from "react-icons/im"
import styled from "styled-components"
import drums from '../loopfiles/DRUMS.mp3'
//import other audio files//

const AudioPlayer = () => {
    const [isPlaying, setIsPlaying] = useState(false);
    const [isLooping, setIsLooping] = useState(false);
    const [isOnMute, setIsOnMute] = useState(false);
    const audioRef = useRef(new Audio(drums));
  
    useEffect(() => {
        if (isOnMute) {
            audioRef.current.volume=0;
        } 
        else {
            audioRef.current.volume=1;
        }
      }, [isOnMute]);
    useEffect(() => {
        if (isPlaying) {
            audioRef.current.play();
        } else {
            audioRef.current.pause();
            audioRef.current.load();
        }
      }, [isPlaying]);
      useEffect(() => {
        if (isLooping) {
            audioRef.current.loop = true;
        } else {
            audioRef.current.loop = false;
        }
      }, [isLooping]);
  return (
    <div> 
        {!isPlaying ? (
        <button type="button" 
        className="play" 
        onClick={() => setIsPlaying(true)}> 
        <ImPlay2></ImPlay2> Play 
        </button>
        ) : (
        <button type="button"
        className="pause"
        onClick={() => setIsPlaying(false)}> 
        <ImStop></ImStop> Stop 
        </button> 
        )}
        <Flex>
            <Switcher selected={isLooping} />
            <Text
            onClick={() => setIsLooping(true)}>
            Loop
            </Text>
            <Text
            onClick={() => setIsLooping(false)}>
            Unloop
            </Text>
        </Flex>
        <Flex>
            <Switcher selected={isOnMute} />
            <Text
            onClick={() => setIsOnMute(true)}>
            Mute
            </Text>
            <Text
            onClick={() => setIsOnMute(false)}>
            UnMute
            </Text>
        </Flex>
    
  

      
            
    </div>
  )
}
const Flex = styled.div`
  margin-top: 5px;
  display: flex;
  align-items: center;
  border-radius: 2px;
  background: grey;
  height: 20px;
  width: 120px;
  position: relative;
  margin-bottom: 5px;
`;
const Switcher = styled.div`
  background: black;
  border-radius: 2px;
  height: 20px;
  line-height: 41px;
  width: 50%;
  cursor: pointer;
  position: absolute;
  transition: 0.5s;
  -webkit-transition: 0.5s;
  -moz-transition: 0.5s;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16);
  z-index: 1;
  left: ${({ selected }) =>
    selected === true ? "0px" : "60px"};
`;

const Text = styled.div`
  color: ${({ selected }) => (selected ? "black" : "white")};
  font-size: 13px;
  font-weight: 20;
  line-height: 4px;
  padding: 30;
  width: 50%;
  text-align: center;
  cursor: pointer;
`;
export default AudioPlayer

PayPal JavaScript SDK button opens about:blank#blocked window in Django template but not in local HTML file

I’ve been trying to integrate PayPal buttons on my Django website, but I keep having this problem where the PayPal popup window appears as about:blank#blocked. I can see this error in console:

popup_open_error_iframe_fallback 
{err: 'n: Can not open popup window - blockedn    at Ie (…owser=false&allowBillingPayments=true:1342:297830', timestamp: '1644780862712', referer: 'www.sandbox.paypal.com', sdkCorrelationID: 'f12370135a997', sessionID: 'uid_d36969c1b2_mtk6mja6mzy', …}

What I don’t understand is that the problem isn’t there if I just open the HTML file itself in a browser… The script looks like this:

<!-- Set up a container element for the button -->
<div id="paypal-button-container" class='text-center mt-2'></div>

<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=blahblahmyid&currency=EUR"></script>

<script>
    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({
        locale: 'it_IT',
        style: {
            color: 'gold',
            shape: 'rect',
            layout: 'vertical',
            label: 'pay'
        },

        // Set up the transaction
        createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: '88.44'
                    }
                }]
            });
        },

        // Finalize the transaction
        onApprove: function(data, actions) {
            return actions.order.capture().then(function(orderData) {
                // Successful capture! For demo purposes:
                console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
                var transaction = orderData.purchase_units[0].payments.captures[0];
                alert('Transaction '+ transaction.status + ': ' + transaction.id + 'nnSee console for all available details');

                // Replace the above to show a success message within this page, e.g.
                // const element = document.getElementById('paypal-button-container');
                // element.innerHTML = '';
                // element.innerHTML = '<h3>Thank you for your payment!</h3>';
                // Or go to another URL:  actions.redirect('thank_you.html');
            });
        }


    }).render('#paypal-button-container');
</script>

What’s the problem ? I don’t understand.

Built-in Constructors and their Prototype —

The activity was to Log Array.prototype and Object.prototype to the console using only the arr variable and the proto property.

So these are the original code:

const arr = [1, 2, 3];

console.log(); // log the Array.prototype
console.log(); // log the Object.prototype

So What I did: I wrote on the first, console.log(arr.__proto__ === Array.prototype);
the second one is, console.log(arr.__proto__ === Object.prototype); but still not right.
It says that in the first log, the Array.prototype is the proto property of any array. the next one, the prototype property of Array.prototype refers to the object.prototype. I can’t figure it out what does it meant. I tried also writing like this: console.log(arr.__proto__ === Object.prototype); still not right. What am I missing here?