Conditional redirect based on POST req submitted by my Chrome Extension?

Viewed 24

I have a chrome extension that sends a fetch post request API I created. The request sends the current URL address to an API.

I want to redirect the user to a page based on the outcome of the of the API response.

API Logic

If the domain already in a database do x.

If not, do y.

Is it possible to return a message/response from node to the frontend tab or popup.html that I can use to create a conditional redirect?

I am really struggling to find a solution for this in the Google Chrome Ex. API docs.

NOTE: the extension sends the request perfectly. This code works. So does the node js code.

NOTE2: The fetch request made by the extension is from a button on the popup.html

Node Script - ideal situation

router.post("/initial", async (req, res, next) => {
    //
    try {
        const body = req.body;
        const website = body.url;
        const clientProject = body.projectName;

        //if domain already exists in main DB
        if (dummyListOfExisitngDomains.includes(website)) {

            //Send rejection message back to client

        } else {
            //Send success message to client
        }
    } catch (err) {
        console.log(err.message);
    }

    //
});


0 Answers
Related