console.log does not show in Backend when trying to use Vercel/Railway?

569 Views Asked by At

This is my code structure:

1

First, I want to say that my code works locally, it only causes problems why I try to deploy on Vercel or Railway. Backend --> first sends user to login page --> goes back to backend to /authorize, then is sent to /callback --> sends user to dashboard.html.

I have an interesting issue where the user ALWAYS MAKES IT to the dashboard.html, but NONE of the console.log in the backend are shown? Even the two console.log right before the last line of code which sends user to dashboard.html.

I have no idea why NO console.log show up???? I have a few in the FRONTEND that ALWAYS show up????? No idea why

I have this piece of backend code:

//authorize the user by getting a code
app.get("/authorize", (req, res) => {
console.log("poopy");
  var auth_query_parameters = new URLSearchParams({
    response_type: "code",
    client_id: client_id,
    scope: "user-top-read",
    redirect_uri: redirect_uri,
  });

  res.redirect(
    "https://accounts.spotify.com/authorize?" + auth_query_parameters.toString()
  );

});

app.get("/callback", (req, res) => {
  const code = req.query.code; //this is from url
  console.log(code);
  console.log("ops");

  var body = new URLSearchParams({
    code: code,
    redirect_uri: redirect_uri,
    grant_type: "authorization_code",
  });
  console.log(client_id + "client id");
  console.log(client_secret + "client secret");
  request.post({
    url: "https://accounts.spotify.com/api/token",
    form: body,
    headers: {
      "Content-type": "application/x-www-form-urlencoded",
      "Authorization":
        "Basic " +
        Buffer.from(client_id + ":" + client_secret).toString("base64"),
    }
    // json: true
  },
  (error, response, body) => {
      const data = JSON.parse(body);
      global.access_token = data.access_token;
      console.log(data + "data");
      console.log(global.access_token  + "access token");
      
      res.sendFile(path.join(__dirname, "frontend", "dashboard.html"));
  });
});

Tried debugging, but never got anywhere? The console when I inspect just doesn't show any of the console.log

0

There are 0 best solutions below