diff --git a/src/module/html/stat/index.ts b/src/module/html/stat/index.ts
new file mode 100644
index 0000000..dec2409
--- /dev/null
+++ b/src/module/html/stat/index.ts
@@ -0,0 +1,11 @@
+/**
+ * 添加统计脚本
+ * @param html
+ * @returns
+ */
+export const addStat = (html: string) => {
+ return html.replace(
+ '',
+ ``,
+ );
+};
diff --git a/src/module/index.ts b/src/module/index.ts
index 581823f..ae4c3e9 100644
--- a/src/module/index.ts
+++ b/src/module/index.ts
@@ -1,4 +1,4 @@
-import { getDNS, isLocalhost } from '@/utils/dns.ts';
+import { getDNS, isIpv4OrIpv6, isLocalhost } from '@/utils/dns.ts';
import http from 'http';
import { UserApp } from './get-user-app.ts';
import { config, fileStore } from '../module/config.ts';
@@ -104,6 +104,13 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
// app = 'codeflow';
// domainApp = true;
} else {
+ if (isIpv4OrIpv6(dns.hostName)) {
+ // 打印出 req.url 和错误信息
+ console.error('Invalid domain: ', req.url, dns.hostName);
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
+ res.end('Invalid domain\n');
+ return res.end();
+ }
// 验证域名
if (dns.hostName !== domain) {
// redis获取域名对应的用户和应用
diff --git a/src/utils/dns.ts b/src/utils/dns.ts
index 19f9de6..5891f30 100644
--- a/src/utils/dns.ts
+++ b/src/utils/dns.ts
@@ -9,3 +9,9 @@ export const getDNS = (req: http.IncomingMessage) => {
export const isLocalhost = (hostName: string) => {
return hostName.includes('localhost') || hostName.includes('192.168');
};
+
+export const isIpv4OrIpv6 = (hostName: string) => {
+ const ipv4 = /^(\d{1,3}\.){3}\d{1,3}$/;
+ const ipv6 = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
+ return ipv4.test(hostName) || ipv6.test(hostName);
+};