. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/raphael/goa"
	"github.com/raphael/goa-middleware/cors"
	"gopkg.in/inconshreveable/log15.v2"
)

var _ = Describe("Middleware", func() {

	Context("with a running goa app", func() {
		var dsl func()
		var method string
		var path string
		var optionsHandler goa.Handler

		var service *goa.GracefulApplication
		var url string
		portIndex := 1

		JustBeforeEach(func() {
			goa.Log.SetHandler(log15.DiscardHandler())
			service = goa.NewGraceful("").(*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))
			service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("", optionsHandler))
			cors.MountPreflightController(service, spec)
			portIndex++
Beispiel #2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/raphael/goa"
	"github.com/raphael/goa/cors"
	"gopkg.in/inconshreveable/log15.v2"
)

var _ = Describe("Middleware", func() {

	Context("with a running goa app", func() {
		var dsl func()
		var method string
		var path string
		var optionsHandler goa.Handler

		var service *goa.GracefulApplication
		var url string
		portIndex := 1

		JustBeforeEach(func() {
			goa.Log.SetHandler(log15.DiscardHandler())
			service = goa.NewGraceful("").(*goa.GracefulApplication)
			spec, err := cors.New(dsl)
			Ω(err).ShouldNot(HaveOccurred())
			service.Use(cors.Middleware(spec))
			router := service.HTTPHandler().(*httprouter.Router)
			h := func(ctx *goa.Context) error { return ctx.Respond(200, nil) }
			router.Handle(method, path, goa.NewHTTPRouterHandle(service, "", "", h))
			router.Handle("OPTIONS", path, goa.NewHTTPRouterHandle(service, "", "", optionsHandler))
			cors.MountPreflightController(service, spec)
			portIndex++