mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-04 13:27:21 +08:00 
			
		
		
		
	Enable CORS on web server
This commit is contained in:
		
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							@ -51,6 +51,7 @@ func startChatServer() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// static files
 | 
						// static files
 | 
				
			||||||
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 | 
						http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
							enableCors(&w)
 | 
				
			||||||
		http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
 | 
							http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if path.Ext(r.URL.Path) == ".m3u8" {
 | 
							if path.Ext(r.URL.Path) == ".m3u8" {
 | 
				
			||||||
@ -66,6 +67,10 @@ func startChatServer() {
 | 
				
			|||||||
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
 | 
						log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func enableCors(w *http.ResponseWriter) {
 | 
				
			||||||
 | 
						(*w).Header().Set("Access-Control-Allow-Origin", "*")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getStatus(w http.ResponseWriter, r *http.Request) {
 | 
					func getStatus(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
	status := Status{
 | 
						status := Status{
 | 
				
			||||||
		Online:                stats.IsStreamConnected(),
 | 
							Online:                stats.IsStreamConnected(),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user