Skip to content

Commit

Permalink
FIX #884 move express-pouchdb to devDepenencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Sep 1, 2019
1 parent da97fe0 commit 46f412f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Bugfixes:
- Fix imports of encryption-plugin to work with rollup [#1413](https://github.com/pubkey/rxdb/issues/1413) Thanks [@kenshyx](https://github.com/kenshyx)
- Removed `express-pouchdb` from the dependencies [#884](https://github.com/pubkey/rxdb/issues/884)

### 8.3.1 (23 August 2019)

Expand Down
1 change: 1 addition & 0 deletions docs-src/custom-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ See: [Tutorial: Using the RxDB Server-Plugin](./tutorials/server.md)
**Do never** expose this server to the internet, use a couchdb-instance at production.

```js
// run 'npm install express-pouchdb' before you use this plugin

// This plugin is not included into the default RxDB-build. You have to manually add it.
import RxDBServerModule from 'rxdb/plugins/server';
Expand Down
6 changes: 6 additions & 0 deletions docs-src/tutorials/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ import * as MemoryAdapter from 'pouchdb-adapter-memory';
RxDB.plugin(MemoryAdapter);
```

You also have to install the module `express-pouchdb` which does not come with RxDB.

```bash
npm install express-pouchdb --save
```


Now we can create a database and a collection.

Expand Down
2 changes: 0 additions & 2 deletions orga/before-next-major.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

This list contains things that have to be done but will create breaking changes.

### Move `pouchdb-server` to devDependencies so the build will not run on each install [issue](https://github.com/pubkey/rxdb/issues/884)

### KeyCompression does not work on objects inside of arrays.
In documents like the following, the properties inside of the array-object will not be compressed `color`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"custom-idle-queue": "2.1.2",
"deep-equal": "^1.0.1",
"express": "4.17.1",
"express-pouchdb": "4.1.0",
"graphql-client": "2.0.1",
"is-electron": "2.2.0",
"is-my-json-valid": "2.20.0",
Expand Down Expand Up @@ -126,6 +125,7 @@
"eslint": "6.3.0",
"exists-file": "3.0.2",
"express-graphql": "0.9.0",
"express-pouchdb": "4.1.0",
"faker": "4.1.0",
"gitbook-cli": "2.3.2",
"graphql": "14.5.4",
Expand Down
21 changes: 15 additions & 6 deletions src/plugins/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import express from 'express';
import ExpressPouchDB from 'express-pouchdb';
import corsFn from 'cors';

import PouchDB from '../pouch-db';
Expand All @@ -14,6 +13,16 @@ Core.plugin(ReplicationPlugin);
import RxDBWatchForChangesPlugin from './watch-for-changes';
Core.plugin(RxDBWatchForChangesPlugin);

let ExpressPouchDB;
try {
ExpressPouchDB = require('express-pouchdb');
} catch (error) {
console.error(
'Since version 8.4.0 the module \'express-pouchdb\' is not longer delivered with RxDB.\n' +
'You can install it with \'npm install express-pouchdb\''
);
}

// we have to clean up after tests so there is no stupid logging
// @link https://github.com/pouchdb/pouchdb-server/issues/226
const PouchdbAllDbs = require('pouchdb-all-dbs');
Expand All @@ -24,17 +33,17 @@ const SERVERS_OF_DB = new WeakMap();
const DBS_WITH_SERVER = new WeakSet();


const normalizeDbName = function(db) {
const normalizeDbName = function (db) {
const splitted = db.name.split('/').filter(str => str !== '');
return splitted.pop();
};

const getPrefix = function(db) {
const getPrefix = function (db) {
const splitted = db.name.split('/').filter(str => str !== '');
splitted.pop(); // last was the name
if (splitted.length === 0) return '';
let ret = splitted.join('/') + '/';
if(db.name.startsWith('/')) ret = '/' + ret;
if (db.name.startsWith('/')) ret = '/' + ret;
return ret;
};

Expand All @@ -43,7 +52,7 @@ const getPrefix = function(db) {
*/
function tunnelCollectionPath(db, path, app, colName) {
db[colName].watchForChanges();
app.use(path + '/' + colName, function(req, res, next) {
app.use(path + '/' + colName, function (req, res, next) {
if (req.baseUrl === path + '/' + colName) {
const to = normalizeDbName(db) + '-rxdb-0-' + colName;
const toFull = req.originalUrl.replace('/db/' + colName, '/db/' + to);
Expand Down Expand Up @@ -78,7 +87,7 @@ export function spawnServer({

if (cors) {
['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS']
.map(method => method.toLowerCase())
.map(method => method.toLowerCase())
.forEach(method => app[method]('*', corsFn()));
}

Expand Down

0 comments on commit 46f412f

Please sign in to comment.