
拥有多个子域的最有效和最有效的方法是什么:
> 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))
选择一个符合您要求的产品.
总结以上是内存溢出为你收集整理的处理在Heroku上托管的Clojure分类Web应用程序的子域全部内容,希望文章能够帮你解决处理在Heroku上托管的Clojure分类Web应用程序的子域所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)