(cors error in axios) How to implement the headers placed by extension on our node js

I am getting cors error while trying to scrape website. When I tried to run the website again by enable cors unblock extension for Chrome it scrapped the data perfectly but it was only for user side while I want it to be client side too anyway to implement what that extension used in my axios header here is the extension I used https://chrome.google.com/webstore/detail/cors-unblock/lfhmikememgdcahcdlaciloancbhjino

And below is the node js code :-

    const axios = require('axios');

const jsdom = require('jsdom');

const {JSDOM} = jsdom;

(async () => {

 const html = await axios.get('https://beemanga.net/latest-update/', {
  method: 'PATCH',mode: 'no-cors',
        headers: {
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', 

            'Accept': 'application/json',
            'Content-Type': 'application/json',

        },
        withCredentials: true,
        credentials: 'same-origin',
        crossdomain: true,

  
 });

Thanks in advance hoping to get some suggestions from your side.

how to get result data from async fetch inside another function

I’m trying to use async fetch call to get data from the server but the result looks like an empty async function. what am I doing wrong?

this is my code

  function initAutoComplete (selector, params = []) {
    let config = {
      selector: selector, 
      data: {
        src: async () => {
          try {
            let myurl = `/component/get_states?country_id=64`; // http://localhost
            const response = await fetch(myurl)
            const source = await response.json();
            console.log('source', source); // ==> this doesn't even appear in the console log
            return source;
          } catch (err) {
            return err;
          }
        },
        keys: ["state_name"],
        cache: true,
      },
    };
    console.log('config', config.data);
    return config;
  }
  const asd = initAutoComplete('#state_name');
  console.log('asd', asd.data);

this is the result in the developer tools
result from developer tools

although when I used postman to test the url, it shows the data as expected

[
    {
        "id": "17",
        "state_name": "Bali",
        "country_name": "Indonesia"
    },
    {
        "id": "16",
        "state_name": "Banten",
        "country_name": "Indonesia"
    },
    {
        "id": "7",
        "state_name": "Bengkulu",
        "country_name": "Indonesia"
    },
]

Need to filter data date wise

I have some query result data like..

"results": [
    {
        "activityId": "7",
        "universityId": "23",
        "studentId": "25",
        "content": "Add course in cart",
        "activityType": "chat",
        "createdAt": "2022-04-10T22:25:29.798Z"
    },
    {
        "activityId": "6",
        "universityId": "17",
        "studentId": "25",
        "content": "Add course in cart",
        "activityType": "chat",
        "createdAt": "2022-04-09T23:48:23.554Z"
    },
    {
        "activityId": "5",
        "universityId": "17",
        "studentId": "25",
        "content": "Add course in cart",
        "activityType": "chat",
        "createdAt": "2022-04-08T23:48:21.841Z"
    }
]

Now I need to filter the data like:

[
  {
    title: 2022-04-10 (here createdAt value),
    value: {
            "activityId": "5",
            "universityId": "17",
            "studentId": "25",
            "content": "Add course in cart",
            "activityType": "chat"
      }
  }
]

I am using nestJS.

const allActivity = [];
      Promise.all(
        results.map((value) => {
          if (allActivity.length <= 0) {
            const obj = {
              title: value.createdAt,
              values: value,
            };
            allActivity.push(obj);
          }
        }),
      );

I just need to filter the data with this format or just need to complete my function that I have written below.

Nextjs inline styles not working when running build

I am working on a nextjs project where I get my styles as inline style tags under head element, but same is not working when i run build and start the server. The inline styles are now bundled in a styles.css file and is requested as a separate network call that I want to avoid.

Any clue why this could be happening:

Here is my package.json:

{
  "name": "abc",
  "description": "xyz",
  "version": "0.1.0",
  "scripts": {
    "dev": "cross-env PORTALCD=xyz ENV=dev next dev",
    "build:qa": "cross-env PORTALCD=xyz ENV=qa next build",
    "build:reg": "cross-env PORTALCD=xyz ENV=reg next build",
    "build:stg": "cross-env PORTALCD=xyz ENV=stg next build",
    "build": "cross-env PORTALCD=xyz ENV=prod next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@license-admin/sem-utilities": "1.21.0",
    "memory-cache": "^0.2.0",
    "next": "12.0.7",
    "node-sass": "^6.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "swr": "^0.5.6"
  },
  "devDependencies": {
    "critters": "^0.0.16",
    "cross-env": "^7.0.2",
    "eslint": "7.32.0",
    "eslint-config-next": "11.0.1",
    "sass": "1.38.2",
    "postcss": "^8.3.6",
  }
}

I also tried the experimental flag mention in this tweet, but did not work as expected.

  1. Add experimental: { optimizeCss: true } to next.config.js
  2. Install [email protected] as a dependency

https://twitter.com/hdjirdeh/status/1369709676271726599/photo/1

How to fetch data from an API using Ajax? [duplicate]

I have an ajax function here :

EventManager.GetLeaveBalance = function (idemployee) {
    $.ajax({
        url: "http://xxx.xxx.xxx:83/GetLeaveBalance/" + idemployee,
        type: "GET",
        dataType: "json",
        contentType: "application/json",
        success: function (data) {
           
            console.log(data);
        }
    });
}

somehow If I call it on console it shows error :

EventManager.GetLeaveBalance(2170)
undefined
EventManager:1 Access to XMLHttpRequest at 'http://xxxx.xxxx.xxxx:83/GetLeaveBalance/2170' from origin 'http://localhost:51130' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
jquery.min.js:4          
GET http://xxxx.xxxx.xxxx:83/GetLeaveBalance/2170 net::ERR_FAILED

can someone help me ? I’m new to API.

uikit offcanvas display initially

I’m creating a react application using uikit framework. The problem is the offcanvas. I want it to be open when the page loads and close when a button clicks. I tried,

UIkit.util.ready(function() {
    UIkit.offcanvas('#offcanvas').show();
});

this. But it gives me this error.
Uncaught ReferenceError: UIkit is not defined

What am i doing wrong. Any help is really appreciated.

How can I paint and include a simple loading until the element component renders?

[How can I paint and include a simple load until two seconds after the Item.js component renders? I’ve tried to do it with conditionals but I can’t find a way

should i do a conditional by creating a state and referring to whether state is true or false run the map on the mambo state array?
]

const ItemList = () => {
const [collection, setCollection] = useState([]);
const [mambos, setMambos] = useState([]);
useEffect(() => {
  const promesa = new Promise((resolve, reject) => {
    setTimeout(() => {
      if (id === "1") {
        resolve(PRODUCTS[0]);
      } else if (id === "2") {
        resolve(PRODUCTS[2]);
      } else if (id === "3") {
        resolve(PRODUCTS[1]);
      } else if (id === "4") {
        resolve(PRODUCTS[3]);
      } else if (id === "5") {
        resolve(PRODUCTS[4]);
      } else {
        reject(
          "Hubo un problema con la carga de elementos, intentalo mas tarde..."
        );
      }
    }, 2000);
  });
  promesa
    .then((rta) => {
        setMambos(rta.items);
        setCollection(rta);
    })
    .catch((err) => err);
}, [id, mambos, collection]);
 
return (
  <div>
    <h1
    >
      <CollectionTitle />
    </h1>
    {mambos.map(({ id, ...otherProps }) => <Item key={id} {...otherProps} />)
    )}
  </div>
);
};

Problem printing ${el }, I want to print the content of the element but it prints $%7Bel%7D

Problem printing ${el }, I want to print the content of the element but it prints $%7Bel%7D.

const heroesJson = [{
    "images": [
    "Abaddon_icon.png",
    "Alchemist_icon.png",
    "Ancient_Apparition_icon.png",
]
}]
const divHeroes = document.querySelector('#heroes')
let html = ''
arrayHeroe = heroesJson[0].images
arrayHeroe.forEach((el)=>{
    html+=`<div><img class='w-20' src="{{url_for('static', filename='img-dota/${el}')}}"></div>`
})
console.log(html)

The console.log prints : “/static/img-dota/$%7Bel%7D.png”….”

how to make array not send empty [duplicate]

hello I have a problem with this array, when doing the push, everything is fine but when I do a console.log to the array it throws me an empty array.

let arrayCsv: any[] = [];


this.photos.forEach( (element) => {
    this.groupsService.getGroup(element.id_group).subscribe(res => {
        arrayCsv.push({
            precio: element.price,
            cantidad: 1,
            descripcion: element.description,
            carpeta: res.name,
            imagen: element.image
        })
    });        
})


console.log(arrayCsv);

this throws me this

enter image description here

but what i need is this

enter image description here

net::ERR_ABORTED 404 (Not Found) After moving the library files

I was trying to use p5js library, if I put my library into a library folder, the error occurs. But if I put it right next to my script2.js file(where the main program is), it works fine.

This gives error:

<script src="../library/p5.js"></script>
<script src="../library/p5.collide2d.js"></script>
<script src="js/script2.js"></script>

This works fine :(Aftering moving p5.js and p5.collide2d.js to js folder(same as script2.js))

<script src="js/p5.js"></script>
<script src="js/p5.collide2d.js"></script>
<script src="js/script2.js"></script>

I have checked the path for both cases, both should be correct(I ctrl+Left clicked on the paths in VS code and successfully opened the library files)
Why is this happening? Any help would be greatly appreciated.