export interface; -w 时自动监听没有content-type的html

This commit is contained in:
Star 2025-12-10 16:56:37 +08:00
parent 069a4b95c2
commit fa97cace29
3 changed files with 227 additions and 226 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module apigo.cc/gojs/service
go 1.24.0 go 1.24.0
require ( require (
apigo.cc/gojs v0.0.30 apigo.cc/gojs v0.0.31
apigo.cc/gojs/console v0.0.4 apigo.cc/gojs/console v0.0.4
apigo.cc/gojs/file v0.0.7 apigo.cc/gojs/file v0.0.7
apigo.cc/gojs/http v0.0.8 apigo.cc/gojs/http v0.0.8

View File

@ -290,8 +290,9 @@ func init() {
onWatchLock.Unlock() onWatchLock.Unlock()
}, "") }, "")
s.SetOutFilter(func(in map[string]any, request *s.Request, response *s.Response, out any, logger *log.Logger) (newOut any, isOver bool) { s.SetOutFilter(func(in map[string]any, request *s.Request, response *s.Response, out any, logger *log.Logger) (newOut any, isOver bool) {
if strings.HasPrefix(response.Header().Get("Content-Type"), "text/html") { contentType := response.Header().Get("Content-Type")
outStr := u.String(out) outStr := u.String(out)
if strings.HasPrefix(contentType, "text/html") || (contentType == "" && strings.Contains(outStr, "<html")) {
if strings.Contains(outStr, "let _watchWS = null") { if strings.Contains(outStr, "let _watchWS = null") {
return nil, false return nil, false
} }

View File

@ -55,7 +55,7 @@ function id(size?: number): string { return '' }
function setTplFunc(fnList: Object): void { } function setTplFunc(fnList: Object): void { }
function tpl(file: string, data: Object): string { return '' } function tpl(file: string, data: Object): string { return '' }
interface Config { export interface Config {
// github.com/ssgo/s 的配置参数 // github.com/ssgo/s 的配置参数
listen: string // 监听端口(|隔开多个监听)(,隔开多个选项如果不指定IP则监听在0.0.0.0如果不指定端口则使用h2c协议监听在随机端口80端口默认使用http协议443端口默认使用https协议例如 80,http|443|443:h2|127.0.0.1:8080,h2c listen: string // 监听端口(|隔开多个监听)(,隔开多个选项如果不指定IP则监听在0.0.0.0如果不指定端口则使用h2c协议监听在随机端口80端口默认使用http协议443端口默认使用https协议例如 80,http|443|443:h2|127.0.0.1:8080,h2c
ssl: Map<string, CertSet> // SSL证书配置key为域名value为cert和key的文件路径 ssl: Map<string, CertSet> // SSL证书配置key为域名value为cert和key的文件路径
@ -134,24 +134,24 @@ interface Config {
ipPrefix: string // discover服务发现时指定使用的IP网段默认排除 172.17.Docker ipPrefix: string // discover服务发现时指定使用的IP网段默认排除 172.17.Docker
} }
interface CertSet { export interface CertSet {
certFile: string certFile: string
keyFile: string keyFile: string
} }
interface PoolConfig { export interface PoolConfig {
min: number min: number
max: string max: string
idle: number idle: number
} }
interface LimiterConfig { export interface LimiterConfig {
from: string from: string
time: number time: number
times: number times: number
} }
interface RegisterOption { export interface RegisterOption {
authLevel: number authLevel: number
host: string host: string
method: string method: string
@ -167,7 +167,7 @@ interface RegisterOption {
onClose: (params: RequestParams) => void onClose: (params: RequestParams) => void
} }
interface RequestParams { export interface RequestParams {
args: Object args: Object
headers: Object headers: Object
request: Request request: Request
@ -178,7 +178,7 @@ interface RequestParams {
logger: Logger logger: Logger
} }
interface OnMessageParams { export interface OnMessageParams {
type: string type: string
data: string | Object data: string | Object
client: WSClient client: WSClient
@ -186,7 +186,7 @@ interface OnMessageParams {
logger: Logger logger: Logger
} }
interface WSClient { export interface WSClient {
id: string id: string
read: () => WSMessage read: () => WSMessage
write: (data: any) => void write: (data: any) => void
@ -195,12 +195,12 @@ interface WSClient {
close: () => void close: () => void
} }
interface WSMessage { export interface WSMessage {
type: string type: string
data: string | Object data: string | Object
} }
interface Session { export interface Session {
set: (key: string | Object, value?: any) => void set: (key: string | Object, value?: any) => void
get: (...keys: string[]) => any | Object get: (...keys: string[]) => any | Object
remove: (...keys: string[]) => void remove: (...keys: string[]) => void
@ -208,7 +208,7 @@ interface Session {
save: () => void save: () => void
} }
interface Caller { export interface Caller {
get(url: string, headers?: Object): Result get(url: string, headers?: Object): Result
head(url: string, headers?: Object): Result head(url: string, headers?: Object): Result
post(url: string, data: any, headers?: Object): Result post(url: string, data: any, headers?: Object): Result
@ -217,7 +217,7 @@ interface Caller {
do(method: string, url: string, data: any, callback?: (data: string) => void, headers?: Object): Result do(method: string, url: string, data: any, callback?: (data: string) => void, headers?: Object): Result
} }
interface Result { export interface Result {
status: string status: string
statusCode: number statusCode: number
headers: Object headers: Object
@ -226,7 +226,7 @@ interface Result {
object(): Object object(): Object
} }
interface CookieOption { export interface CookieOption {
path: string path: string
domain: string domain: string
expires: any expires: any
@ -235,7 +235,7 @@ interface CookieOption {
httpOnly: boolean httpOnly: boolean
} }
interface Request { export interface Request {
id: string id: string
proto: string proto: string
scheme: string scheme: string
@ -264,7 +264,7 @@ interface Request {
setUserID: (id: string) => void setUserID: (id: string) => void
} }
interface Response { export interface Response {
id: string id: string
setStatus: (code: number) => void setStatus: (code: number) => void
setCookie: (name: string, value: string, option?: CookieOption) => void setCookie: (name: string, value: string, option?: CookieOption) => void
@ -279,14 +279,14 @@ interface Response {
end: (data: any) => void end: (data: any) => void
} }
interface Logger { export interface Logger {
debug: (message: string, info?: Object) => void debug: (message: string, info?: Object) => void
info: (message: string, info?: Object) => void info: (message: string, info?: Object) => void
warn: (message: string, info?: Object) => void warn: (message: string, info?: Object) => void
error: (message: string, info?: Object) => void error: (message: string, info?: Object) => void
} }
interface UploadFile { export interface UploadFile {
name: string name: string
size: number size: number
data: any data: any