加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

处理在Heroku上托管的Clojure分类Web应用程序的子域

发布时间:2020-12-14 23:25:01 所属栏目:资源 来源:网络整理
导读:我有一个分类的clojure网络应用程序我想在Heroku上托管.该域名在Godaddy注册. 拥有多个子域的最有效和最有效的方法是什么: newyork.classapp.com montreal.classapp.com paris.classapp.com …… 用户,所有逻辑,应该跨子域共享,所以我希望只有一个代码库.
我有一个分类的clojure网络应用程序我想在Heroku上托管.该域名在Godaddy注册.

拥有多个子域的最有效和最有效的方法是什么:

> newyork.classapp.com
> montreal.classapp.com
> paris.classapp.com
> ……

用户,所有逻辑,应该跨子域共享,所以我希望只有一个代码库.

将子域重定向到第一级文件夹很容易,如下所示:
paris.classapp.com – > classapp.com/paris/

但我希望用户在浏览网站时继续看到子域名,如下所示:
paris.classapp.com/cars/blue-car-to-sell

与此相反:classapp.com/paris/cars/blue-car-to-sell

我该怎么办?

解决方法

Heroku支持通配符子域: https://devcenter.heroku.com/articles/custom-domains#wildcard-domains.

您将在主机头中包含原始域,您可以使用类似(完全未经测试)的内容:

(GET "/" {{host "host"} :headers} (str "Welcomed to " host))

您还可以创建自己的路由MW(完全未经测试):

(defn domain-routing [domain-routes-map]
   (fn [req]
       (when-let [route (get domain-routes-map (get-in req [:headers "host"]))]
           (route req))))

并使用类似的东西:

(defroutes paris  
    (GET "/" [] "I am in Paris"))
 (defroutes new-new-york
    (GET "/" [] "I am in New New York"))

 (def my-domain-specific-routes 
    (domain-routing {"paris.example.com" paris "newnewyork.example.com" new-new-york}))

另一个选择是创建一个“mod-rewrite”MW,在进入Compojure路线之前修改uri:

(defn subdomain-mw [handler]
    (fn [req]
        (let [new-path (str (subdomain-from-host (get-in req [:headers "host"])
                            "/"
                            (:uri req))]
             (handler (assoc req :uri new-path))))  

  (defroutes my-routes  
      (GET "/:subdomain/" [subdomain] (str "Welcomed to " subdomain))

选择一个符合您要求的产品.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读