Example #1
0
// Start a file server for serving HTML, CSS and JS files
func StartFileServer(hostAndPort string, corsHostAndPort string) {
	log.Printf("Starting HTTP server on %s", hostAndPort)

	mux := http.NewServeMux()
	mux.Handle("/", middleware.NewCorsHandler(corsHostAndPort, http.FileServer(http.Dir("static"))))

	server := &http.Server{
		Addr:    hostAndPort,
		Handler: mux,
	}
	server.ListenAndServe()
}
Example #2
0
// Configure a new server that is ready to be started.
func NewServer(opts ...option) *Server {
	server := &Server{
		httpServer: &http.Server{
			ReadTimeout:  2 * time.Second,
			WriteTimeout: 2 * time.Second,
		},
		eventStore:     NewNullEventStore(),
		servicesConfig: []ServiceConfig{},
	}

	for _, opt := range opts {
		opt(server)
	}

	mux := http.NewServeMux()
	mux.Handle("/", middleware.NewCorsHandler(server.corsHostAndPort, newEventBusRequestHandler(server.servicesConfig, server.eventStore)))
	mux.Handle("/ws", newWebSocketHandler(server.corsHostAndPort))
	server.httpServer.Handler = mux

	return server
}