如何找出 React 网站的端口号保存在哪里?

如何找出 React 网站的端口号保存在哪里?

我有一台 Debian 机器,我可以看到 React 网站正在端口 4173 上运行,但找不到它在哪里,因此我无法更改端口。

我认为它在某个配置文件中。

  • 它不在package.json
{
  "name": "debiantest",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview --host"
  },
  "dependencies": {
    "react": "^18.0.0",
    "react-dom": "^18.0.0"
  },
  "devDependencies": {
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "@vitejs/plugin-react": "^1.3.0",
    "vite": "^2.9.5"
  }
}
  • 我没有找到此端口或站点/etc/nginx/sites-enabled/default

  • 使用 grep 我发现这个数字是node_modules/caniuse-lite/data/agents.js

"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","tC","",""],E:"KaiOS 浏览器",F:{tC:1527811200}}}; node_modules/vite/dist/node/chunks/dep-3397b401.js: const port = (_b = options.port) !== null && _b !== void 0 ? _b : 4173;

但我不确定我会在哪里改变它。

我还可以在哪里查找这个端口号?

答案1

停止 React 服务器进程,然后使用 strace 重新启动它。这会有点吵,但您需要查找“open”调用。这将向您显示 React 服务器在运行时打开的所有文件。其中一个文件应该包含配置数据。

以下是使用库存 Apache HTTPD 服务器的示例:

strace -f httpd 2>&1 | grep open

将显示 httpd 进程打开了许多文件,查看这些文件,您可以在其中找到有价值的信息:

open("/etc/httpd/conf/httpd.conf", O_RDONLY|O_CLOEXEC) = 3
open("/etc/httpd/conf.d/ssl.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/httpd/conf.d/perl.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/httpd/conf.d/php.conf", O_RDONLY|O_CLOEXEC) = 4

这只是一个例子,React 服务器会有不同的文件,但你应该能够过滤它们(即 grep -v)直到找到有用的内容。

相关内容