temp
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/module/html/stat/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/module/html/stat/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | /** | ||||||
|  |  * 添加统计脚本 | ||||||
|  |  * @param html | ||||||
|  |  * @returns | ||||||
|  |  */ | ||||||
|  | export const addStat = (html: string) => { | ||||||
|  |   return html.replace( | ||||||
|  |     '</head>', | ||||||
|  |     `<script defer src="https://umami.xiongxiao.me/script.js" data-website-id="79e7aa98-9e6e-4eef-bc8b-9cbd0ecb11c3"></script></head>`, | ||||||
|  |   ); | ||||||
|  | }; | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| import { getDNS, isLocalhost } from '@/utils/dns.ts'; | import { getDNS, isIpv4OrIpv6, isLocalhost } from '@/utils/dns.ts'; | ||||||
| import http from 'http'; | import http from 'http'; | ||||||
| import { UserApp } from './get-user-app.ts'; | import { UserApp } from './get-user-app.ts'; | ||||||
| import { config, fileStore } from '../module/config.ts'; | import { config, fileStore } from '../module/config.ts'; | ||||||
| @@ -104,6 +104,13 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR | |||||||
|     // app = 'codeflow'; |     // app = 'codeflow'; | ||||||
|     // domainApp = true; |     // domainApp = true; | ||||||
|   } else { |   } 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) { |     if (dns.hostName !== domain) { | ||||||
|       // redis获取域名对应的用户和应用 |       // redis获取域名对应的用户和应用 | ||||||
|   | |||||||
| @@ -9,3 +9,9 @@ export const getDNS = (req: http.IncomingMessage) => { | |||||||
| export const isLocalhost = (hostName: string) => { | export const isLocalhost = (hostName: string) => { | ||||||
|   return hostName.includes('localhost') || hostName.includes('192.168'); |   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); | ||||||
|  | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user