-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add normal HTTP handler for debugging purposes
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !js | ||
|
||
package workers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
// Server serves http.Handler as a normal HTTP server. | ||
// if the given handler is nil, http.DefaultServeMux will be used. | ||
// As a port number, PORT environment variable or default value (9900) is used. | ||
// This function is implemented for non-JS environments for debugging purposes. | ||
func Serve(handler http.Handler) { | ||
if handler == nil { | ||
handler = http.DefaultServeMux | ||
} | ||
port := os.Getenv("PORT") | ||
if port == "" { | ||
port = "9900" | ||
} | ||
addr := fmt.Sprintf(":%s", port) | ||
fmt.Printf("listening on: http://localhost%s\n", addr) | ||
fmt.Fprintln(os.Stderr, "warn: this server is currently running in non-JS mode. to enable JS-related features, please use the make command in the syumai/workers template.") | ||
http.ListenAndServe(addr, handler) | ||
} |