pouchdb / express-pouchdb

⚠️⚠️⚠️ THIS REPO HAS MOVED ⚠️⚠️⚠️
143 stars 52 forks source link

Application Cache breaks Sync #421

Closed AndreasHohnholt closed 7 years ago

AndreasHohnholt commented 7 years ago

Hi @ll,

when my HTML5 App (i just use the example TODO APP from pouchdb.com) uses an appcache manifest file the sync between the local pouchdb and the remote pouchdb (express-pouchdb) breaks. The debugger of the chrome reports this error:

pouchdb-6.1.1.min.js:9 GET https://HOST/_db/todos/?_nonce=1485504253133 net::ERR_FAILED

Has anyone any ideas to solve this?

Please note that the express app is behind a nginx with basic auth.

Here are the code files for a better understanding:

express index.js:

const express = require('express');
const app = express();
const PouchDB = require('pouchdb');
const path = require('path');
const url = require('url');

const PORT = 8080;
const DB_URL = '/_db';

express.static.mime.define({'text/cache-manifest': ['appcache']});

var pouchHandle = require('express-pouchdb')(PouchDB , {
  mode: 'fullCouchDB', // specified for clarity. It's the default so not necessary.
  overrideMode: {
    exclude: [
      'routes/authentication',
      // disabling the above, gives error messages which require you to disable the
      // following parts too. Which makes sense since they depend on it.
      'routes/authorization',
      'routes/session'
    ]
  }
});

new PouchDB('todos');

app.use(DB_URL, pouchHandle);

app.use('/app', express.static('public_html'));

app.listen(PORT);

Some parts of the TODO index,js

(function() {

  'use strict';

  var ENTER_KEY = 13;
  var newTodoDom = document.getElementById('new-todo');
  var syncDom = document.getElementById('sync-wrapper');

  // EDITING STARTS HERE (you dont need to edit anything above this line)

  var db = new PouchDB('todos');
  var remoteCouch = new PouchDB('https://HOST/_db/todos', {
  ajax: {
    cache: false,
    timeout: 10000,
  },
  auth: {
    username: "user",
    password: "pass"
  }
});

  // Initialise a sync with the remote server
  function sync() {
  syncDom.setAttribute('data-sync-state', 'syncing');
  /*
  var opts = {live: true};
  db.replicate.to(remoteCouch, opts, syncError);
  db.replicate.from(remoteCouch, opts, syncError);  
  */
PouchDB.sync(db, remoteCouch , {
  live: true,
  retry: true
}).on('change', function (info) {
  console.log(info);
}).on('paused', syncError).on('active', syncError).on('denied',syncError).on('complete', function (info) {
  console.log(info);
}).on('error', syncError);  
}

TODO appcache file:

CACHE MANIFEST
#23.01.2017 - v1

index.html
js/base.js
js/app.js
js/pouchdb-6.1.1.min.js
style/base.css
style/bg.png

nginx default:

server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;
        return 301 https://$host$request_uri;
}

server {
        listen 443;
        server_name HOST;

        ssl on;
        # Use certificate and key provided by Let's Encrypt:
        ssl_certificate /etc/letsencrypt/live/HOST/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/HOST/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

        # Pass requests for / to localhost:8080:
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:8080/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
          auth_basic "Restricted Content";
              auth_basic_user_file /etc/nginx/.htpasswd;    
        }
}
AndreasHohnholt commented 7 years ago

Solve the problem.

I just have to add

NETWORK: *

to the appcache file ;-)