43
43
tempToolsPath = createToolsDir ()
44
44
port string
45
45
portSSL string
46
+ origins = flag .String ("origins" , "" , "Allowed origin list for CORS" )
46
47
)
47
48
48
49
type NullWriter int
@@ -53,7 +54,7 @@ type logWriter struct{}
53
54
54
55
func (u * logWriter ) Write (p []byte ) (n int , err error ) {
55
56
h .broadcastSys <- p
56
- return 0 , nil
57
+ return len ( p ) , nil
57
58
}
58
59
59
60
var logger_ws logWriter
@@ -109,6 +110,20 @@ func main() {
109
110
iniflags .Parse ()
110
111
}
111
112
113
+ // move CORS to config file compatibility, Vagrant version
114
+ if * origins == "" {
115
+ log .Println ("Patching config.ini for compatibility" )
116
+ f , err := os .OpenFile (dest + "/" + * configIni , os .O_APPEND | os .O_WRONLY , 0666 )
117
+ if err != nil {
118
+ panic (err )
119
+ }
120
+ _ , err = f .WriteString ("\n origins = http://webide.arduino.cc:8080\n " )
121
+ if err != nil {
122
+ panic (err )
123
+ }
124
+ f .Close ()
125
+ restart ("" )
126
+ }
112
127
//log.SetFormatter(&log.JSONFormatter{})
113
128
114
129
log .SetLevel (log .InfoLevel )
@@ -194,8 +209,14 @@ func main() {
194
209
195
210
socketHandler := wsHandler ().ServeHTTP
196
211
212
+ extraOriginStr := "https://create.arduino.cc, http://create.arduino.cc, https://create-dev.arduino.cc, http://create-dev.arduino.cc, http://create-staging.arduino.cc, https://create-staging.arduino.cc,"
213
+
214
+ for i := 8990 ; i < 9001 ; i ++ {
215
+ extraOriginStr = extraOriginStr + " http://localhost:" + strconv .Itoa (i ) + ", https://localhost:" + strconv .Itoa (i )
216
+ }
217
+
197
218
r .Use (cors .Middleware (cors.Config {
198
- Origins : "https://create.arduino.cc, http://create.arduino.cc, https://create-dev.arduino.cc, http://create-dev.arduino.cc, http://webide.arduino.cc:8080, http://create-staging.arduino.cc, https://create-staging.arduino.cc, http://localhost:8989, https://localhost:8990" ,
219
+ Origins : * origins + "," + extraOriginStr ,
199
220
Methods : "GET, PUT, POST, DELETE" ,
200
221
RequestHeaders : "Origin, Authorization, Content-Type" ,
201
222
ExposedHeaders : "" ,
@@ -270,7 +291,7 @@ const homeTemplateHtml = `<!DOCTYPE html>
270
291
var log = document.getElementById('log');
271
292
var pause = document.getElementById('myCheck');
272
293
var messages = [];
273
- var only_log = false ;
294
+ var only_log = true ;
274
295
275
296
function appendLog(msg) {
276
297
0 commit comments