-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
93 lines (78 loc) · 1.92 KB
/
conf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package server
import (
"crypto/tls"
"errors"
"io/fs"
"net/http"
"os"
)
type ServeConfig struct {
Port uint `json:"port"`
Root string `json:"root"`
File string `json:"file"`
CORS bool `json:"cors"`
HTTPS bool `json:"https"`
HistoryApiFallback bool `json:"historyApiFallback"`
Proxy []ProxyMiddleware `json:"proxy"`
Server Server `json:"server"`
// TODO
Host string `json:"host"`
IsYarn bool `json:"isYarn"`
// internal
Internal internalConfig `json:"-"`
LocalAddress string `json:"-"`
NetworkAddress string `json:"-"`
HttpProtocol string `json:"-"`
WebsocketProtocol string `json:"-"`
}
type Server struct {
// file name only, not path
Cert string `json:"cert"`
Key string `json:"key"`
// logger
Debug bool `json:"debug"`
Color bool `json:"color"`
}
type ProxyMiddleware struct {
Prefix string `json:"prefix"`
Target string `json:"target"`
ChangeOrigin bool `json:"changeOrigin"`
Secure bool `json:"secure"`
}
type internalConfig struct {
CertPath string `json:"-"`
KeyPath string `json:"-"`
}
func getInsecureTransport() http.RoundTripper {
initOnce.Do(func() {
insecureTransport = http.DefaultTransport.(*http.Transport).Clone()
insecureTransport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
})
return insecureTransport
}
func getCacheDir(sc ServeConfig) (string, error) {
cwd, err := os.Getwd()
if err != nil {
return "", err
}
// TODO: check if package.json
isNodePkg := true
_, err = os.Stat(cwd + "/" + nodePkgFile)
if err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return "", err
}
isNodePkg = false
}
if !isNodePkg {
// TODO
return ".cache/yalive-server", nil
}
if sc.IsYarn {
// TODO
return ".yarn/.cache/yalive-server", nil
}
return "node_modules/.cache/yalive-server", nil
}