Using the same subdomain name in multiple routes AWS

Currently, in my API I have two very similar routes:

  1. GET /history
  2. GET /purchase/history?id=1

When ran locally the two routes are seen as a distinct from each other executing different logic. After deploying to my AWS lambda, the two routes are no longer seen as distinct and the logic for route 1, also runs for route 2. Is this some type of AWS policy that enforces distinct names for routes? Or is there something I’m missing?

Uncaught SyntaxError: Unexpected end of JSON input ReactJs

I basically want to local store an useState hook

function App() {
  const [folders, setFolders] = useState(
    () => JSON.parse(localStorage.getItem("folders")) || []
  );

  // store the value into the localStorage whenever folders is updated
  useEffect(() => {
    localStorage.setItem("folders", JSON.stringify(folders));
  }, [folders]);
return (
....
)

But it gives me an error
enter image description here

How can I refactor React page to individually add/edit Faq question/answers?

I am NOT a React/website developer but I hired someone to make a static React website for me where I can edit the text/images myself. I do program in node/javascript however..

However in the case of my FAQ (frequently asked questions) page it seems they made a function that repeats the same text 9 times and I am unable to individually customize each row’s question and answer???

Can someone please help me refactor this code so that I can add/edit more rows with a question and answer format?

You will notice that each question is a clickable row that reveals the answer to each question (see image).

Thank you!

enter image description here

import { useState } from "react"
import "./FaqPage.scss"

export default function FaqPage() {
  const [faqRow, setfaqRow] = useState(0)
  const faqToggle = (data) => {
    console.log(data)
    setfaqRow(data)
  }
  return (
    <>
      <section className="innerBAnner">
        <div className="container">
          <div className="row">
            <div className="col-12">
              <h1>Frequently asked questions</h1>
            </div>
          </div>
        </div>
      </section>

      <section className="aboutPage">
        <div className="aboutLayerTwo">
          <div className="container">
            <figure className="mb-xl-5 mb-xl-5">
              <img src="img/img13.png" alt="" className="w-100 d-block" />
            </figure>
            <div className="row align-items-center pt-md-5"></div>
            <div className="row">
              {[0, 1, 2, 3, 4, 5, 6, 7, 8].map((data, ind) => (
                <div className="col-md-12">
                  <div className="faq-row">
                    <div
                      className="d-flex align-items-end  faq-head"
                      onClick={() => faqToggle(ind)}
                    >
                      <b>0{ind + 1}</b>
                      <h4 className="me-auto">
                        Lorem Ipsum is simply dummy text of the printing?
                      </h4>
                      <span>
                        {faqRow === ind ? (
                          <svg
                            width="19"
                            height="30"
                            viewBox="0 0 19 30"
                            fill="none"
                            xmlns="http://www.w3.org/2000/svg"
                          >
                            <path
                              d="M18.1189 14.6937L16.4545 12.95L4.40707 0.268555L0.731445 3.75596L11.1243 14.6937L0.731445 25.6315L4.40707 29.1189L16.4545 16.4374L18.1189 14.6937Z"
                              fill="#353535"
                            />
                          </svg>
                        ) : (
                          <svg
                            width="29"
                            height="18"
                            viewBox="0 0 29 18"
                            fill="none"
                            xmlns="http://www.w3.org/2000/svg"
                          >
                            <path
                              d="M14.4254 17.3875L16.1691 15.723L28.8506 3.67563L25.3632 -1.52439e-07L14.4254 10.3928L3.48764 -1.10865e-06L0.000232541 3.67563L12.6817 15.723L14.4254 17.3875Z"
                              fill="#353535"
                            />
                          </svg>
                        )}
                      </span>
                    </div>
                    {faqRow === ind && (
                      <div className="faq-body">
                        <p>
                          XXXXX Lorem Ipsum is simply dummy text of the printing
                          and typesetting industry. Lorem Ipsum has been the
                          industry's standard dummy text ever since the 1500s,
                          when an unknown printer took a galley of type and
                          scrambled it to make a type specimen book. It has
                          survived not only five centuries, but also the leap
                          into electronic typesetting, remaining essentially
                          unchanged.
                        </p>
                        <p>
                          Lorem Ipsum is simply dummy text of the printing and
                          typesetting industry. Lorem Ipsum has been the
                          industry's standard dummy text ever since the 1500s,
                          when an unknown printer took a galley of type and
                          scrambled it to make a type specimen book.
                        </p>
                      </div>
                    )}
                  </div>
                </div>
              ))}
            </div>
          </div>
        </div>
      </section>
    </>
  )
}

creating the 2 different version of my mern application

I am working on an application with react on the frontend and MongoDB for the database. The main motto of this application is to be a place where students can come and see some of the research that is happening at my university, but I don’t want everyone to have the access to edit or delete the pdf files. So, my questions are:

  1. What are some of the ways to upload the pdf file in react form to be stored in MongoDB database?
  2. What are some ways to have only one person authorized to upload and edit the pdf and others only see them? Or maybe have a 2 version of the web application where one has an extra column to either edit/delete the pdf files or so on?

Please let me know.
Thank you!

Check if user has a data for Economy Bot discord.js

Heyo, I’m coding on an Economy-System right now but I have a problem.
I have to check if the user has data and if he doesn’t have data create it.
Here is what I’ve done:

if (UserJSON.user[message.author.id]) { //It doesn't detect the message.author.id
  console.log("User Data already exists");
  return;
} else {
    const newUser = {
      user: message.author.id,
      stats: {
        money: 0
      }  
    }
    UserJSON.push(newUser);
    fs.writeFileSync("./data/users.json", JSON.stringify(UserJSON, null, 2));
}

The writing data function works perfectly as you can see down here in the users.json

[
  {
    "user": "654022997983756328",
    "stats": {
      "money": 0
    }
  },
  {
    "user": "917065319724507176",
    "stats": {
      "money": 0
    }
  }
]

The only problem is “check if the user has data”
It doesn’t detect

[message.author.id]

Someone told me to do

if (UserJSON.[message.author.id].user) {

but sadly it didn’t work too.
Can anyone help me here fix this issue?

scrollIntoView shifting whole page to the left, exposing white screen. Happing only in Google Chrome

I have a roadmap component where bars are arranged by time in horizontal axis (and by anything depending on filters for vertical axis)
I am trying to scroll to an HTMLElement using scrollIntoView. The scrolling involves both vertical and horizontal scrolling.
I am using scrollIntoView method.

roadmapItemEl.scrollIntoView({ block: 'center', inline: 'center', behavior: 'auto' });

It generally works as expected. However, when it autoscrolls to a bar in the right side of the current activeElement, the whole page shifts to the left, exposing white space. This happens only in Chrome.
(Note: I tried all combinations of the scrollIntoView options. Nothing changed)

Normal:
enter image description here

After autoscroll to a bar on the right:
enter image description here
(Note: This only gets fixed if I autoscroll to a bar on the left)

I unfortunately cannot share much code, thus I don’t expect complete hand-holding here. However, I just need to know what to look for. Here are my questions:

  1. What is this white space part of exactly? (body?) Can it be rid of?
  2. In what situations does this generally occur?
  3. Are there alternatives to scrollIntoView that could be more suitable for such autoscrolling (more fine-tuned for horizontal scroll perhaps?)?
  4. Probable reason why only Chrome is affected.

How do I automatically pull a picture of an actor in HTML/Javascript?

I am trying to automatically pull a picture of a randomly generated actor/actress and put that picture source in an div. I will use flask/jinja to generate the random actor/actress using a SQL query and import that name into my html.

Is there an API to use or should I be looking in the direction of something like:
<img src=”SOMETHING HERE” + {{ actorName }} > ?

Selenium 3.141.0 – send_keys() work fine on Windows but don’t on Linux Debian 11

I try to do some web automation with Selenium.

My program was working good until I upgrade my packages – Now the send_keys() don’t work on linux but it do well on Windows with the same versions.

I tried to click(),clear(),send_keys() – copy/pasting, etc…

But none of these make the javascript input saving my send_keys(string). It do send the keys, but after he goes to next action, string has gone… And there’s no error in console neither in logs.

It work perfectly under windows with/out headless, but it has stop working on Debian 11 Rolling after an update…

Please give me hint it’s very important !!

Selenium version 3.141.0
Chrome version 100.0.4896.88-1
Python version 3.9.12
Kernel version 5.16.0

How to import .js files into “commands.js” file for Office ribbon add-in?

I can not figure out how to import .js files into the commands.js file in an office js add-in.

Using the ES6 standard in the taskpane.js file was not a problem, for example in taskpane.js:

import * as tools from "./scripts/native/tools.js"

worked without any issues.

In commands.js, this way of importing won’t work. I get a “SyntaxError: Unexpected token ‘*’. import call expects exactly one argument.” error. I read that I should add type=”module” in the commands.html file as such:

<script type="module" src="commands.js" type="text/javascript"></script> 

This breaks the ribbon-commands functionality and I get a new error: “Failed to load resource: the server responded with a status of 404 (Not Found)”.

However, if I mistype the path on purpose I get the following new error “[webpack-dev-server] ERROR in ./src/commands/commands.js 17:0-52
Module not found: Error: Can’t resolve ‘./scripts/native/toolss.js’ in ‘/Users/eberhardtkorf/dev/redacted/new/src/commands'”.

This makes it seem like the file can be found, but for some reason it won’t be imported as an external module.

A way around this is to write all code in the commands.js file, but this is not scalable and not desirable.

Any help will be appreciated.

Nodejs – Spotify API Refresh Token

First off. I have not worked with APIs before.

The problem I have is to refresh the token. The code that’s returned as a query parameter to the redirect URI seems to be needed to be put in manually each time. When I get that authentication code, the code below gets me the new access token, as well as the refresh token.

The package I use is spotify-web-api-node and the code below is a result of following their readme. I have also tried spotify-oauth-refresher but I’m too new to coding to figure it out how to use it.

I’ve tried following the guide on Spotify’s own website as well. But I don’t seem to be able to get this right by myself.

Would love some guidance. Thanks.
Hope things are clear.

 var scopes = ['user-read-private', 'user-read-email', 'playlist-read-private', 'playlist-modify-private'],
      redirectUri = '<redirect uri>',
      clientId = '<client id>',
      clientSecret = '<client secret>',
      state = '<random string>';
    
    var spotifyApi = new SpotifyWebApi({
      redirectUri: redirectUri,
      clientId: clientId,
      clientSecret: clientSecret
    });
    
    // Create the authorization URL
    var authorizeURL = spotifyApi.createAuthorizeURL(scopes, state);
    
    console.log(authorizeURL);
    
    var credentials = {
      clientId: '<client id>',
      clientSecret: '<client secret>',
      redirectUri: '<redirect uri>'
    };
    
    var spotifyApi = new SpotifyWebApi(credentials);
    
    // The code that's returned as a query parameter to the redirect URI
    var code = 'I HAVE TO MANUALLY PUT THIS IN WHEN THE DURATION RUNS OUT';
    
    // Retrieve an access token and a refresh token
    spotifyApi.authorizationCodeGrant(code).then(
      function(data) {
        console.log('The token expires in ' + data.body['expires_in']);
        console.log('The access token is ' + data.body['access_token']);
        console.log('The refresh token is ' + data.body['refresh_token']);
    
        // Set the access token on the API object to use it in later calls
        spotifyApi.setAccessToken(data.body['access_token']);
        spotifyApi.setRefreshToken(data.body['refresh_token']);
      },
      function(err) {
        console.log('Something went wrong!', err);
      }
    );
    
    // clientId, clientSecret and refreshToken has been set on the api object previous to this call.
    spotifyApi.refreshAccessToken().then(
      function(data) {
        console.log('The access token has been refreshed!');
    
        // Save the access token so that it's used in future calls
        spotifyApi.setAccessToken(data.body['access_token']);
      },
      function(err) {
        console.log('Could not refresh access token', err);
      }
    );

Understanding some debugging items in developer console

I created a function and prototype with the following:

function Range(from, to) {
    if (new.target === undefined) {
        throw new Error("Range must be invoked with new.")
    }
    Object.assign(this, {from, to});
}
Range.prototype = {
    includes: function(x) {
        return x >= this.from && x <= this.to;
    },
    toString: function() {
        return `[${this.from}, ${this.to}]`;
    }
}

And here is what it shows in Chrome’s Console:

enter image description here

If we use the includes function as an example, the name is the function name and the length is the arity of the function. And [[FunctionLocation]] seems to be part of the underlying implementation of the JS engine, so not important for actual js debugging. But then what are the following:

  • Caller? What would be an example of when that would be non-null.
  • Arguments? Again, what would be an example of when that would be non-null