Meteor.js deploy to “example.com” or “www.example.com”?

前端 未结 4 1835
鱼传尺愫
鱼传尺愫 2020-12-04 07:18

I recently deployed a meteor app using the following command:

$ meteor deploy example.com

and later (thinking that it was the same) using t

4条回答
  •  日久生厌
    2020-12-04 07:47

    Okay guys, I found a simple way :

    If you want www to redirect to non-www you can use this method. You can also modify the code a little to do it other way around.

    Simply set

    @ (CNAME) : origin.meteor.comm
    www (CNAME) : origin.meteor.com
    

    Then, deploy your main app (without www).

    meteor deploy yourapp.com
    

    Now, create a new meteor app called redirect with

    meteor create redirect
    cd redirect
    

    Set the generated js file contents like this :

    if (Meteor.isClient) {
      var url = document.URL;
      url = url.replace("www.", "");
      window.location.href = url;
    }
    

    Then deploy your redirect app (with www)

    meteor deploy www.yourapp.com
    

    What you did is, you deployed two different applications to www and non-www of your domain. All the meteor app at www does is to redirect you to non-www domain. It will also redirect www.yourapp.com/some/path to yourapp.com/some/path. Simple yet powerfull solution :)

提交回复
热议问题