简体   繁体   English

Ember 2路由子域

[英]Ember 2 Routing Subdomains

I have a Ember 2 application (ember-cli) that uses a Rails API as the back end. 我有一个Ember 2应用程序(ember-cli),它使用Rails API作为后端。 For this application, I have enabled Wildcard DNS with my DNS Provider (Cloudflare). 对于此应用程序,我已使用我的DNS提供程序(Cloudflare)启用了通配符DNS。 When a user signs up with my website, I want them to be able to use their subdomain to access their public home page. 当用户注册我的网站时,我希望他们能够使用他们的子域来访问他们的公共主页。

For example: 例如:

A user named Steve signs up for my site located at awesome.com . 名为Steve的用户注册了位于awesome.com我的网站。 So Steve browses to steve.awesome.com , which internally would translate to awesome.com/users/steve . 因此史蒂夫浏览了steve.awesome.com ,内部将转换为awesome.com/users/steve How do I setup my Ember routes such that it can route based off of the subdomain? 如何设置我的Ember路线,以便它可以基于子域路由?

I have come to a solution, but it isn't exactly what I was initially looking for. 我已经找到了解决方案,但这并不是我最初想要的。 I realized there really isn't a reason why the URL has to be awesome.com/users/steve , and instead have decided that their subdomain (or custom domain) will act as their identifier. 我意识到URL确实没有理由为awesome.com/users/steve ,而是决定他们的子域(或自定义域)将充当他们的标识符。 So let's say Steve browses to steve.awesome.com , I will figure out the host via window.location.hostname , and use that as a lookup key to pass to my Rails API and retrieve user data. 所以让我们说史蒂夫浏览steve.awesome.com ,我将通过window.location.hostname找出主机,并将其作为查找键传递给我的Rails API并检索用户数据。

Not exactly the solution I originally was seeking, but it solves my issue! 不完全是我最初寻求的解决方案,但它解决了我的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM