@@ -101,60 +101,48 @@ func handleSignal(server *http.Server) {
101
101
}
102
102
103
103
func replaceServerConf () {
104
- //err := filepath.Walk(filepath.ToSlash(filepath.Join(model.Conf.StaticRoot, "theme")), func(path string, f os.FileInfo, err error) error {
105
- // if strings.HasSuffix(path, ".min.js.tpl") {
106
- // data, e := ioutil.ReadFile(path)
107
- // if nil != e {
108
- // logger.Fatal("read file [" + path + "] failed: " + err.Error())
109
- // }
110
- // content := string(data)
111
- // if !strings.Contains(content, "http://localhost:5897") {
112
- // return err
113
- // }
114
- //
115
- //
116
- // content = strings.Replace(content, "http://localhost:5897", model.Conf.Server, -1)
117
- // content = strings.Replace(content, "")
118
- // if e = ioutil.WriteFile(path, []byte(content), 0644); nil != e {
119
- // logger.Fatal("replace server conf in [" + path + "] failed: " + err.Error())
120
- // }
121
- // }
122
- //
123
- // return err
124
- //})
125
- //if nil != err {
126
- // logger.Fatal("replace server conf in [theme] failed: " + err.Error())
127
- //}
128
-
129
- paths , err := filepath .Glob (filepath .ToSlash ("console/dist/*.js.tpl" ))
104
+ path := "theme/sw.min.js"
105
+ data , err := ioutil .ReadFile (path )
106
+ if nil != err {
107
+ logger .Fatal ("read file [" + path + "] failed: " + err .Error ())
108
+ }
109
+ content := string (data )
110
+ content = strings .Replace (content , "http://server.tpl.json" , model .Conf .Server , - 1 )
111
+ content = strings .Replace (content , "http://staticserver.tpl.json" , model .Conf .StaticServer , - 1 )
112
+ content = strings .Replace (content , "${StaticResourceVersion}" , model .Conf .StaticResourceVersion , - 1 )
113
+ if err = ioutil .WriteFile (path , []byte (content ), 0644 ); nil != err {
114
+ logger .Fatal ("replace sw.min.js in [" + path + "] failed: " + err .Error ())
115
+ }
116
+
117
+ paths , err := filepath .Glob ("console/dist/*.js.tpl" )
130
118
if 0 < len (paths ) {
131
119
for _ , path := range paths {
132
- data , e := ioutil .ReadFile (path )
133
- if nil != e {
120
+ data , err := ioutil .ReadFile (path )
121
+ if nil != err {
134
122
logger .Fatal ("read file [" + path + "] failed: " + err .Error ())
135
123
}
136
124
content := string (data )
137
125
content = strings .Replace (content , "http://server.tpl.json" , model .Conf .Server , - 1 )
138
126
content = strings .Replace (content , "http://staticserver.tpl.json" , model .Conf .StaticServer , - 1 )
139
127
writePath := strings .TrimSuffix (path , ".tpl" )
140
- if e = ioutil .WriteFile (writePath , []byte (content ), 0644 ); nil != e {
128
+ if err = ioutil .WriteFile (writePath , []byte (content ), 0644 ); nil != err {
141
129
logger .Fatal ("replace server conf in [" + writePath + "] failed: " + err .Error ())
142
130
}
143
131
}
144
132
}
145
133
146
134
if util .File .IsExist ("console/dist/" ) { // not exist if npm run dev
147
- err = filepath .Walk (filepath . ToSlash ( "console/dist/" ) , func (path string , f os.FileInfo , err error ) error {
135
+ err = filepath .Walk ("console/dist/" , func (path string , f os.FileInfo , err error ) error {
148
136
if strings .HasSuffix (path , ".html.tpl" ) {
149
- data , e := ioutil .ReadFile (path )
150
- if nil != e {
137
+ data , err := ioutil .ReadFile (path )
138
+ if nil != err {
151
139
logger .Fatal ("read file [" + path + "] failed: " + err .Error ())
152
140
}
153
141
content := string (data )
154
142
content = strings .Replace (content , "http://server.tpl.json" , model .Conf .Server , - 1 )
155
143
content = strings .Replace (content , "http://staticserver.tpl.json" , model .Conf .StaticServer , - 1 )
156
144
writePath := strings .TrimSuffix (path , ".tpl" )
157
- if e = ioutil .WriteFile (writePath , []byte (content ), 0644 ); nil != e {
145
+ if err = ioutil .WriteFile (writePath , []byte (content ), 0644 ); nil != err {
158
146
logger .Fatal ("replace server conf in [" + writePath + "] failed: " + err .Error ())
159
147
}
160
148
}
0 commit comments