CouchDB URL Rewriting for SEO - ajax

I'm trying to create an entire site hosted purely on CouchDB (no nginx reverse proxy either) using a lot of client side Jquery/AJAX magic. Now I'm in the process of making it SEO friendly. I'm using vhosts and URL rewrites to route traffic from the root to my index.html file:
vhost:
example.com /dbname/_design/dd/_rewrite/
In my rewrite definition:
rewrites:[
{
"from": "/db/*",
"to": "/../../../*",
"query": {
}
},
{
"from": "/",
"to": "../../static/index.html",
"query": {
}
}
]
When optimizing a site for SEO, Google requires you to do a few things:
Use the hashbang (#!) in your friendly URL to tell the web crawler that you are an AJAX site with web crawlable material: http://example.com/index.html#!home
Use an http query argument to provide an HTML escaped fragment of that AJAX page: http://example.com/index.html?_escaped_fragment=home
I tried the following with no luck:
rewrites:[
{
"from": "/db/*",
"to": "/../../../*",
"query": {
}
},
{
"from": "/",
"to": "../../static/index.html",
"query": {
}
}, /* FIRST ATTEMPT */
{
"from": "/?_escaped_fragment=:_escaped_fragment",
"to": "/_show/escaped_fragment/:_escaped_fragment",
"query": {
}
}, /* SECOND ATTEMPT */
{
"from": "/?_escaped_fragment=*",
"to": "/_show/escaped_fragment/*",
"query": {
}
}, /* THIRD ATTEMPT */
{
"from": "/",
"to": "/_show/escaped_fragment/:_escaped_fragment",
"query": {
}
}
]
From what I've seen, CouchDB's URL rewriter is not capable of distinguishing the difference between a URLs with args and no args. Has anyone had luck creating such a rule with CouchDB URL rewrites?

I don't have a answer to the question, but I've developed a solution for the bigger problem of making crawlable sites hosted on CouchDB. It is a system that makes use of Facebook's React, list and show functions, ajax on the client and window.history to render the same HTML components filled with data at CouchDB and at the browser:
https://github.com/fiatjaf/reactive-couch
This solution doesn't need the hashbang, because for each unique URL the browser navigates to, using ajax and window.history or simple links (be it _list/listName/viewName/_show/displayKind/c305ee4d-8611-4e08-b9d3-3318835632a9 or something rewritten as /name//kind/c305ee4d-8611-4e08-b9d3-3318835632a9), the server can render the pertinent content.

Related

Vercel - rewrite route to external page

I have a question about rewrite configurations on Vercel, very similar to this vercel discussion. My problem is essentially the same but reverse:
I have a site on vercel (main.vercel.app), and I would like to rewrite different pages to other vercel sites. So what I want is:
main.vercel.app/page-a --> page-a.vercel.app
main.vercel.app/page-b --> page-b.vercel.app
When I tried this configuration, it would correctly load the page, but all the assets (page-a.vercel.app/styles.css etc.) would not be loaded:
{
"rewrites": [
{
"source": "/page-a",
"destination": "https://page-a.vercel.app/"
}
]
}
When I tried this configuration, it would redirect all the assets, but not the initial page:
{
"rewrites": [
{
"source": "/page-a(.*)",
"destination": "https://page-a.vercel.app$1"
}
]
}
So what's the correct configuration supposed to be?
What if you try merging the two rewrites?
According to you, one rewrite pattern is correct for the main page, and the other is for all other assets other than the main page. Since rewrites is a list and can hold multiple patterns, try merging the two objects and making it something like this:
{
"rewrites": [
{
"source": "/page-a",
"destination": "https://page-a.vercel.app/"
},
{
"source": "/page-a(.*)",
"destination": "https://page-a.vercel.app$1"
}
]
}

How to use DSL query from Kibana dev-tools in visualisation?

I have successfully aggregated and queried a particular content I needed in Kibana Dev Tools. However, I need this information in a tabular form either as CSV or PDF. For this, I need to run the DSL query I constructed in Dev Tools in visualisation tool of Kibana. However, I am not able to do it.
I tried copying the DSL to the Lucene query text box on the top part of the visualisation page and also tried within the add filter option. Both way it returns an error.
The query that works in Dev Tools:
{
"query": {
"bool": {
"must": [
{ "match": { "start_datetime":"1569868200" }}
]
}
},
"aggs" : {
"state_location" : {
"terms": {
"field" : "state_location"
},
"aggs": {
"stakeholder_category": {
"terms": {
"field": "stakeholder_category"
},
"aggs": {
"coverage_category": {
"terms": {
"field": "category_paragraph_name.keyword"
}
}
}
}
}
}
}
}
Expecting to get the result on visualisation screen as a table, so that I can export it to CSV or PDF.
The search bar in the discovery bar doesn't work with the json-syntax of a search request towards the REST-API. Instead it uses a simple lucene syntax.
However, you still can edit your search in the discovery manually:
You should be able to see a button with the label "Inspect" like in the following figure.
Note that the look & feel of Kibana got a significant update, so depending of the version you are using, you will find the Inspect button somewhere else in the discovery)
By hitting the button, a right-sided pane will show up with three tabs (Statistics, Request and Response). In the Request-section you can paste your query. Be sure NOT to past the root "query"-node of your json.
Hope, this will help you :-)

How to use normal string to match a regexp string with elasticsearch

I stored a document in elasticsearch, one of whose fields is a regexp expression, then I hope to use a normal string to hit the document, is it possible?
For example, in elasticsearch, there is one document like :
{
"service_id": "service1",
"regexp_url": "abc.*"
}
then I hope to use the string "abcde" to hit the document, is it possible?
The detail user case is:
I have a website and each page is corresponding to a service, also different pages can also corresponded to the same service.
Now I have an es index, it contains two fields: service_id, regexp_url (it means the page's url matched the url regexp will be mapped to the service), now I open a page with url: "abcde", and the document is like above, I want to hit the document to find the serviceId.
POST <INDEX>/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"regexp": {
"<YOUR_FIELD>": {
"value": "<YOUR_REGEX_PATTER"
}
}
}
]
}
}
More Reference :https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

couchapp: Different rewrites for URLs with and without forward slash

Basically, I want two different rewrite rules for these URLs: http://127.0.0.1:5984/test/_design/myapp/_rewrite/docs/abc
http://127.0.0.1:5984/test/_design/myapp/_rewrite/docs/abc/
The first one will be rewritten as http://127.0.0.1:5984/test/_design/myapp/_show/single/abc while the second one will be rewritten as http://127.0.0.1:5984/test/_design/myapp/_list/container/all
I tried doing this:
{
"---": "Container Retrieval",
"method": "GET",
"from": "/docs/*/",
"to": "/_list/basic-container/all"
}
Both of the URLs (with and without the forward slash) redirect to http://127.0.0.1:5984/test/_design/myapp/_list/container/all. It seems like couchDB ignores the forward slash at the end of the URL.
What are the possible solutions to this problem?
The asterisk catches the whole following path. Try the following instead:
{
"method": "GET",
"from": "/docs/:id",
"to": "/_show/single/:id"
},
{
"method": "GET",
"from": "/docs/:id/",
"to": "/_list/basic-container/all"
}

CouchDB Rewriting

I have a URL for my website, which is as follows: http://ashgavs.cloudant.com/site/_design/AshGavsCouch/main/index.html
I added a field to my design document called rewrites and it's as follows:
[
{
"from": "",
"to": "main/index.html"
}
]
However when I go to this URL: http://ashgavs.cloudant.com/site/_design/AshGavsCouch/ . The rewrite isn't happening. Am I doing it wrong? Is there a way to see where its rewriting to so that I can debug this?
As mentioned in the docs the default rewrite is from /site/_design/AshGavsCouch/_rewrite. If you want the rewrite to be from /site/_design/AshGavsCouch/ then you need to specify the URL in your "from" field.

Resources