iris: [BUG] CORS doesn't support Subdomains

Summary

I attempted to host my assets directory as a Subdomain, which Chrome complained requires CORS. So, I followed the example code within the repository (which, btw, doesn’t work on a Party, but only on the entire server, so is incompatible with subdomains), and found that it doesn’t work at all.

Screenshot

image

Versions, etc.

Thing Version
Golang 1.14.6 linux/amd64
Iris master d0d7679
Kernel 5.7.14-200.fc32.x86_64
OS Fedora 32 Workstation

Sample Code

	c := cors.New(cors.Options{
		AllowedOrigins: []string{
			*domain,
			fmt.Sprintf("www.%s", *domain),
			fmt.Sprintf("your.%s", *domain),
		},
		AllowCredentials: true,
	})
	app.WrapRouter(c.ServeHTTP)

	// define subdomain "your."
	your := app.Subdomain("your")
	your.Use(requestid.New())

	// host the ./public directory as subdomain `static.`
	assets := app.Subdomain("static")
	assets.HandleDir("/", iris.Dir("./public"), iris.DirOptions{
		Compress:  true,
		DirList:   iris.DirList,
		IndexName: "/index.html",
		ShowList:  false,
		Cache: iris.DirCacheOptions{
			Enable:          true,
			CompressIgnore:  iris.MatchImagesAssets,
			CompressMinSize: 1,
			Encodings:       []string{"gzip", "br", "deflate", "snappy"},
		},
	})

	// redirect root domain to `your.`
	app.SubdomainRedirect(app, your)

	// Redirect www subdomains to `your.`
	app.SubdomainRedirect(app.Subdomain("www"), your)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

And again, thank you for all the effort you put forward to deal with people like me, hahaha. I really genuinely appreciate it. WIthout you, I would still be struggling through mixing together bits of gin and other frameworks to get yet another duct-taped application server into the wild.

You are always welcomed @AlbinoGeek , we are just scratching the surface! There is always place for improvements, this is what I love about programming. Yes…lets not talk about other “frameworks” they are just routers 😃. Iris is a wise choice, not only because of its performance & features but also the almost real-time support and fixes you get, if you post an issue in any other repo you will get an answer after a lot of days (if you get any)… so I can totally feel you and that’s why I am here.

I will follow your comments and update all subdomains examples with more comments, the godocs already contain enough information but will take look what can be improved over there too.

As per the second instance, I can’t do this, because of my self-imposed TLS-behind-NAT hell, but that is a topic for another issue.

Look the code better, the application is running on :80, the hosts thing is request-based so why not run behind NATS?

BTW: I am preparing a new function that can be declared anywhere and will accept a map ( so you have all the hosts redirection logic in one spot), it will act as a router specifically for subdomain/different domain across multiple Iris Application instances (that are not listening/running), in the end all that will be exposed to a single host:port.