|
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
|
@@ -109,6 +110,20 @@ func main() {
|
109 | 110 | iniflags.Parse()
|
110 | 111 | }
|
111 | 112 |
|
| 113 | + // move CORS to config file compatibility |
| 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("\norigins = 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\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 := "" |
| 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: "",
|
|
0 commit comments