J
J
Juniorrrrr2021-12-17 18:16:06
Node.js
Juniorrrrr, 2021-12-17 18:16:06

What hostname should be specified on the server?

Please tell me, I developed a local project with a simple code

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = https.createServer(async (req, res) => {
  try {
    if (req.method == 'GET') {
      switch (urlParts.pathname) {
        case "/":
            res.writeHead(200, {"Content-Type": "text/plain"});
            res.end("everythink is ok");
             break;
        default:
          res.end("404");
              break;
      }
    }
    else {
      res.end("404");
    }
  } catch (error) {
    console.log("error", error);
  }
});

server.listen(port, hostname, () => {
  console.log(`Server стартанул at http://${hostname}:${port}/`);
});


Then I bought a hosting and a domain, tied the DNS. test template that provides hosting - works
Uploaded all the files to the server, including index.html and server.js.
Now I raise the node process on the server by specifying the file with the code, node server.js, it is written in the logs that the server has started, but the server does not listen to requests that fly from the front.

Example request from the front https://testdomain.net/?link=123 I guess the problem is that the host that I specified in the server.js file is not equal to the domain. But if I specify a host equal to the domain, then I cannot start the server, an error occurs . Tell me please, what am I doing wrong?



61bca9965a32c257138664.png

I do not have a general view of the picture, so I'm trying to deploy the site on the server for the first time

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question