Error with my server file - Invalid URL: index.js

Viewed 632

I am getting the following error when trying to run my server (index.js):

Error: TypeError [ERR_INVALID_URL]: Invalid URL: index.js

The code block is here:

app.get('/:url', async function (req, res) {
      
      try {
    
      
        return res.status(200).json(data);
    
      } catch (ex) {
        console.log(ex);
        return res.status(500).json({ message : "Oops." });
        
      }

With the specific line of code it is referring to is:

const site = await .open(decodeURIComponent(req.params.url));

Has anyone ever encountered this error before, and have any idea how to fix it in this context? Not sure how it is throwing an error for my entire index.js server

Note: This is an express app

2 Answers

The value of req.params.url is index.js.

A web browser can expand index.js into an absolute URL because it knows that it can use the URL of the current HTML document as the base URL.

You're running your code in Node.js. It doesn't run inside a document. There is no base URL.

You need to provide an absolute URL (e.g. http://example.com/index.js) yourself.

That said, I suspect wappalyzer may require that you give it the URL to an HTML document not a JS file.

Well, since there isn't much that i can see about your usage, I'm just going to assume you went to something like http://localhost/index.js.

The problem now is, that wappalyzer does not actually get a valid url. It gets index.js without any form of protocol (http/https/ws/wss...). This means it doesn't know what to do and tells you that the url you provided is invalid.

In order to fix this go to http://localhost/https%3A%2F%2Flocalhost%2Findex.js or append https:// or something similar to your parameter.

Related