func main() { // Create service service := goa.New("API") logger := log15.New() goa.Log = goalog15.New(logger) // Setup middleware service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.Recover()) cspec, err := cors.New(func() { cors.Origin("*", func() { cors.Resource("/*", func() { cors.Headers("Accept", "Content-Type", "Origin", "Authorization") cors.Methods("GET", "POST", "PUT", "DELETE", "OPTIONS") cors.MaxAge(600) cors.Credentials(true) cors.Vary("Http-Origin") }) }) }) if err != nil { panic(err) } // mount the cors controller service.Use(cors.Middleware(cspec)) cors.MountPreflightController(service, cspec) // Mount "authentication" controller c := NewAuthenticationController(service) app.MountAuthenticationController(service, c) // Mount "operands" controller c2 := NewOperandsController(service) app.MountOperandsController(service, c2) // Mount "ui" controller ui.MountController(service) // Mount Swagger spec provider controller swagger.MountController(service) // Start service, listen on port 8080 service.ListenAndServe(":8080") fmt.Println("a ...interface{}") }
var service *goa.GracefulApplication var url string portIndex := 1 JustBeforeEach(func() { goa.Log.SetHandler(log15.DiscardHandler()) service = goa.NewGraceful("", false).(*goa.GracefulApplication) spec, err := cors.New(dsl) Ω(err).ShouldNot(HaveOccurred()) service.Use(cors.Middleware(spec)) h := func(ctx *goa.Context) error { return ctx.Respond(200, nil) } ctrl := service.NewController("test") service.ServeMux().Handle(method, path, ctrl.HandleFunc("", h, nil)) service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("", optionsHandler, nil)) cors.MountPreflightController(service, spec) portIndex++ port := 54511 + portIndex url = fmt.Sprintf("http://localhost:%d", port) go service.ListenAndServe(fmt.Sprintf(":%d", port)) // ugh - does anyone have a better idea? we need to wait for the server // to start listening or risk tests failing because sendind requests too // early. time.Sleep(time.Duration(100) * time.Millisecond) }) AfterEach(func() { service.Shutdown() }) Context("handling GET requests", func() {