couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Broerse <i...@martinbroerse.com>
Subject Re: pushState in CouchDB for Ember
Date Wed, 28 Oct 2015 15:43:58 GMT
Hoi Ingo,

I changed your rewrite rule to this:

[
  {
    "from": "assets/*",
    "to": "assets/*",
    "method": "GET"
  },
  {
    "from": "fonts/*",
    "to": "fonts/*",
    "method": "GET"
  },
  {
    "from": "crossdomain.xml",
    "to": "crossdomain.xml",
    "method": "GET"
  },
  {
    "from": "robots.txt",
    "to": "robots.txt",
    "method": "GET"
  },
  {
    "from": "*/",
    "to": "index.html",
    "method": "GET"
  },
  {
    "from": "",
    "to": "index.html",
    "method": "GET"
  }
]

It seems to work for all Ember App's. Even with more deeply nested routes.

Thanks for your help.


- Martin

On Sun, Oct 25, 2015 at 11:16 PM, Ingo Radatz <thewhorn@googlemail.com>
wrote:

> Hi Martin,
>
> good news! - i have a local copy of your application up and running. Btw.
> my fan is freaking out - some of our reloading code causes heavy load but
> anyway - here is what you have to do:
>
> # 1st - to use the rewrite handler your root url is
>
> https://martinic.cloudant.com/bloggttest/_design/bloggrtest/_rewrite
>
> You can use your custom API from the rewrites.json in parallel with
> CouchDB’s native API - but you must remember when is which API in use.
>
>
> # 2nd - change the root URL in your index.html base-url meta tag
>
> <base href="/bloggttest/_design/bloggrtest/_rewrite/" />
>
>
> # 3th - extend the rewrites.json as follows
>
> [
>    {
>        "from": "fonts/*",
>        "to": "fonts/*",
>        "method": "GET"
>    },
>    {
>        "from": "assets/*",
>        "to": "assets/*",
>        "method": "GET"
>    },
>    {
>        "from": "/",
>        "to": "index.html",
>        "method": "GET"
>    }
> ]
>
>
> Now, your app will start when you request
>
> https://martinic.cloudant.com/bloggttest/_design/bloggrtest/_rewrite/
>
> in the browser. Your router forwards via pushState functionality to /posts
> and i can choose particular posts like
> /posts/7DFFB605-62CD-9D72-B376-5D3729E21904.
>
> And now i want to draw a line. Nothing of this enables
> "pushState-on-CouchDB”. It would work also without the CouchDB rewrite
> rules. But now comes the part where you want that to allow your readers to
> bookmark a blog post e.g.
>
>
> https://martinic.cloudant.com/bloggttest/_design/bloggrtest/_rewrite/posts/7DFFB605-62CD-9D72-B376-5D3729E21904
>
> When they load this bookmark they will get:
>
> {"error":"not_found","reason":"missing”}
>
> Now you can add the following rule to the rewrites.json
>
>    {
>        "from": “/posts/*",
>        "to": "index.html",
>        "method": "GET"
>    }
>
> It will always deliver the same index.html. Your ember router must know
> the real root url and match to the route /posts/:id. The router have to act
> the same way automatically in the initial load as i have manually by
> clicking your blog post link.
>
>
> Hope that helps.
> Ingo
>
>
> > On 25 Oct 2015, at 14:25, Martin Broerse <info@martinbroerse.com> wrote:
> >
> > Hi Ingo,
> >
> > I am setting my first steps here. Do I have to activate rewrite rules
> for it is not working yet.
> >
> > https://martinic.cloudant.com/bloggttest/_design/bloggrtest/
> > https://martinic.cloudant.com/bloggttest/_design/bloggrtest/index.html
> >
> > When they start working do I need rules to exclude:
> >
> https://martinic.cloudant.com/bloggttest/_design/bloggrtest/crossdomain.xml
> > https://martinic.cloudant.com/bloggttest/_design/bloggrtest/assets/*
> > https://martinic.cloudant.com/bloggttest/_design/bloggrtest/fonts/*
> >
> > Thanks,
> >
> > - Martin
> >
> > On Mon, Oct 19, 2015 at 7:51 PM, Martin Broerse <info@martinbroerse.com>
> wrote:
> > Hi Ingo,
> >
> > I will try it and report back, Thanks.
> >
> > - Martin
> >
> > On Mon, Oct 19, 2015 at 5:57 PM, Ingo Radatz <thewhorn@googlemail.com>
> wrote:
> > Hi Martin!
> >
> > pushState is a client-side feature and has no requirements on the
> server-side. Period.
> >
> > I think what all the server-side related configurations want to enable
> is the following:
> >
> > > Unfortunately if a user bookmarks or refresh a page on an app that’s
> using HTML5 pushstate,
> > > it makes a request to the server for that deep linked content.
> > > Here are the rewrites for [put our preferred server into - lets say
> CouchDB] to internally redirect that call
> > > to the same html file. Browser thinks its a unique page but it’s the
> same.
> >
> > In other words: If you want to allow deep-linking (e.g. for bookmarks)
> you have to respond any request with always the same index.html. One of the
> first things you have to do when your JavaScript code executes is to
> analyse the current path in the address bar and change the state of our
> webapp accordingly (e.g. you trigger a route in our client-side router).
> >
> > How could you do that with a CouchDB rewrite handler?
> >
> > Just introduce a fetch-all rule to the rewrite.json
> >
> > [{
> >   “from”: “*”
> >   “to”: “index.html”,
> >   “method”: “GET"
> > }]
> >
> > The rule assumes you have the index.html attached to the same ddoc the
> rewrite.json is included. If its attached to a different doc you can go to
> the resource like
> >
> > [{
> >   “from”: “*”
> >   “to”: “../../other_doc_id/index.html”,
> >   “method”: “GET"
> > }]
> >
> > Hope that helps, ingo
> >
> > > On 19 Oct 2015, at 11:21, Martin Broerse <info@martinbroerse.com>
> wrote:
> > >
> > > Hi Ingo,
> > >
> > > To get pushState to work clientside with for example Apache as a
> server you have to something like this.
> > >
> > > https://github.com/broerse/ember-cli-blog/blob/master/public/.htaccess
> > >
> > > Are you saying pushState works out of the box? Then I like to rephrase
> my question to "How do I write a rewriterule to support pushState?"
> > >
> > > - Martin
> > >
> > >
> > > On Mon, Oct 19, 2015 at 10:33 AM, Ingo Radatz <thewhorn@googlemail.com>
> wrote:
> > > Hi Martin
> > >
> > > > I can't seem to find CouchDB documentation on pushState
> > > > so pointers are welcome.
> > >
> > > Hm. You talking about a client-side related functionality of the
> browsers. So maybe it isn’t surprising that you cannot find anything about
> it in a server-side related documentation. The client-side part of a
> Couchapp are just the static resources (HTML/CSS/IMG/FONTS/…) that are
> attached to a doc (mostly a ddoc). Which brings us to the next statement:
> > >
> > > > I think it is time to move my index.html file and .js files to
> CouchDB.
> > >
> > > Attach them to any doc you want. Some uses a ddoc, others a normal
> doc. If you want to access your index.html (perhaps with rewrite rules) you
> have to know the _id of the doc you have attached to - so, i would
> recommend to not using a UUID for this doc.
> > >
> > > Ingo
> > >
> >
> >
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message