How to retrieve the penultimate redirected URL
See original GitHub issueHi,
This has been discussed before somewhat in a previous thread (https://github.com/node-fetch/node-fetch/issues/978). I have what I thought was a very simple problem that I am struggling to resolve. Full disclosure, I am very new to coding.
I am trying to GET the redirected temporary URL with status 302 code that displays just prior to my webpage. I then need to parse the URL to get a certain query parameter for a subsequent POST call.
My app is built with ReactJS as frontend and express/nodejs as backend.
I have noted the below https://github.com/node-fetch/node-fetch/issues/978
but what I am struggling with is to understand how to get this code to run when I am on subdirectory “/webpage”.
This may be very very wrong, but what I have attempted is the below. I’ve adapted the code from the above thread as a function
export var url = `https://<mywebpage>/webpage`;
function script () {
var response = fetch(previousURL, {
method: 'GET',
}).then(response => {
console.log(response.url).else(error => console.log(error))});
return (response.url);
};
export default script();
I have then written the below code so this function loads when my “/webpage/” loads:
const express = require('express');
const app = express();
const script = require("./script.js");
app.get('/webpage', (req, res) => {
script();
})
app.listen(3000);
Really appreciate any help 😃))
Issue Analytics
- State:
- Created a year ago
- Comments:5
Hi Jimmy,
Thanks for the suggestion. I’ve tried the above, but I’m still not getting the previous (status 302) redirect url returned.
I guess you are looking for: