0

I have a Node.js backend deployed on Render.com, and it is giving me an error when I make requests to it from my frontend application. The backend code works fine on my local machine, and I have checked the logs on Render.com, but I cannot figure out what the issue is. Here is the relevant code for the backend:

const instagramGetUrl = require("instagram-url-direct")

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');

const app = express();

// middleware
const corsOptions = {
    origin: "https://downloadgram.onrender.com" // frontend URI (ReactJS)
}
app.use(express.json());
app.use(cors(corsOptions));

// Parse incoming request bodies as JSON
app.use(bodyParser.json());

const getMediaUrl = async (inputURL) => {
    try {
        let links = await instagramGetUrl(inputURL);
        // console.log(links)
        return new Promise((resolve, reject) => {
            // some asynchronous operation here
            // ...
            // const result = 42; // the value you want to return
            resolve(links); // wrap the value in a resolved Promise
        });
    } catch (error) {
        // Handle the error
        console.error(error);
        // Return a rejected Promise
        return Promise.reject(error);
    }
};

app.post('/', async (req, res) => {
    try {
        const inputURL = req.body.inputValue;
        const links = await getMediaUrl(inputURL);
        res.json({ links: links.url_list });
    } catch (error) {
        console.error(error);
        res.status(500).json({ error: 'Internal server error-> ' + error });
    }
});


// Start the server
app.listen(5001, () => {
    console.log('Server listening on port 5001');
});

Error has been consoled using console.error() in the catch block of getMediaURL() function, error is- Request failed with status code 403

You can check my complete repository here- https://github.com/yogeskumar/downloadgram website url- https://downloadgram.onrender.com/

I have already checked my frontend code and confirmed that the request is being sent to the correct URL. Can someone please help me identify the issue and suggest how to fix it? Thank you in advance.

I have searched many questions on stackoverflow like this but my error is totally different, I am using instagram-url-direct which has axios as its dependency but I think this error is not related to axios

yogesh kumar
  • 103
  • 10

0 Answers0