Пример #1
0
func init() {
	// Configure logging for appengine
	goa.Log.SetHandler(log15.MultiHandler(
		log15.StreamHandler(os.Stderr, log15.LogfmtFormat()),
		AppEngineLogHandler()),
	)

	// Create goa application
	service := goa.New("cellar")

	// Setup CORS to allow for swagger UI.
	spec, err := cors.New(func() {
		cors.Origin("*", func() {
			cors.Resource("*", func() {
				cors.Methods("GET", "POST", "PUT", "PATCH", "DELETE")
				cors.Headers("*")
			})
		})
	})
	if err != nil {
		panic(err)
	}

	// Setup basic middleware
	service.Use(goa.RequestID())
	service.Use(AppEngineLogCtx())
	service.Use(cors.Middleware(spec))
	service.Use(goa.Recover())

	// Mount account controller onto application
	ac := controllers.NewAccount(service)
	app.MountAccountController(service, ac)

	// Mount bottle controller onto application
	bc := controllers.NewBottle(service)
	app.MountBottleController(service, bc)

	// Mount Swagger Spec controller onto application
	swagger.MountController(service)

	// Mount CORS preflight controllers
	cors.MountPreflightController(service, spec)

	// Setup HTTP handler
	http.HandleFunc("/", service.HTTPHandler().ServeHTTP)
}
Пример #2
0
		It("sets the resource origin", func() {
			Ω(spec).Should(HaveLen(1))
			Ω(spec[0]).ShouldNot(BeNil())
			Ω(spec[0].Origin).Should(Equal(origin))
			Ω(spec[0].Path).Should(Equal(path))
			Ω(spec[0].IsPathPrefix).Should(BeFalse())
		})

		Context("Headers", func() {
			headers := []string{"X-Foo", "X-Bar"}

			BeforeEach(func() {
				dsl = func() {
					cors.Origin(origin, func() {
						cors.Resource(path, func() {
							cors.Headers(headers[0], headers[1])
						})
					})
				}
			})

			It("sets the resource headers", func() {
				Ω(spec).Should(HaveLen(1))
				Ω(spec[0]).ShouldNot(BeNil())
				Ω(spec[0].Headers).Should(HaveLen(len(headers)))
				for i, h := range spec[0].Headers {
					Ω(h).Should(Equal(headers[i]))
				}
			})
		})