t08-find-devserver.mjs 1.0 KB

1234567891011121314151617181920
  1. // 只读探针:找出本仓库(mountElementId = tvt-app)的 dev server 到底在哪个端口。
  2. // 判据:首页 HTML 里出现 tvt-app(本仓库)而不是 app(别的项目)。
  3. const PORTS = [5173, 5174, 8719, 8301, 9801, 3000, 8080, 8000, 4173, 7001]
  4. for (const port of PORTS) {
  5. const base = `http://127.0.0.1:${port}`
  6. try {
  7. const controller = new AbortController()
  8. const timer = setTimeout(() => controller.abort(), 4000)
  9. const res = await fetch(base + '/', { signal: controller.signal })
  10. clearTimeout(timer)
  11. const html = await res.text()
  12. const isThisRepo = html.includes('tvt-app')
  13. const isOther = /id="app"/.test(html)
  14. const title = (html.match(/<title>([^<]*)<\/title>/i) || [, ''])[1]
  15. console.log(`${String(port).padEnd(6)} ${res.status} tvt-app=${isThisRepo} otherApp=${isOther} title="${title.slice(0, 40)}"`)
  16. } catch (error) {
  17. console.log(`${String(port).padEnd(6)} 不可达 (${error.name === 'AbortError' ? '超时' : error.message})`)
  18. }
  19. }