TX028

主机被阻止

控制台

Text.js error TX028: Blocked request. This host (…) is not allowed. Add it to `…` in text.config.ts.

发生原因

text dev 以及绑定到回环地址(默认设置)的 text start,只响应发往 localhost、*.localhost 名称或 IP 地址的请求。这可防止 DNS 重绑定攻击。收到的请求使用了其他 Host 请求头,通常来自隧道、反向代理或局域网主机名。

修复方法

在 text.config.ts 中允许该主机。text dev 读取 Vite 的 vite.server.allowedHosts,text start 读取 server.allowedHosts。开头的 . 表示允许子域名:

text.config.tsts
import { defineConfig } from "@textjs/app";export default defineConfig({  // text dev  vite: { server: { allowedHosts: ["my-laptop.local", ".ngrok.app"] } },  // text start  server: { allowedHosts: [".example.com"] },});

text start --host 使用回环地址以外的任何地址时都会跳过此检查。参见使用代理。