-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: use pouchdb-session-authentication for session
- Loading branch information
1 parent
00825e3
commit 6b6cdd3
Showing
5 changed files
with
98 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,18 @@ | ||
const { Headers } = require('cross-fetch'); | ||
const PouchDB = require('pouchdb-core'); | ||
PouchDB.plugin(require('pouchdb-adapter-http')); | ||
PouchDB.plugin(require('pouchdb-mapreduce')); | ||
PouchDB.plugin(require('pouchdb-session-authentication')); | ||
|
||
const ArchivingDB = require('./archiving-db'); | ||
const environment = require('./environment'); | ||
|
||
const sessionCookieAwareFetch = () => (url, opts = {}) => { | ||
const sessionToken = environment.sessionToken; | ||
|
||
if (sessionToken) { | ||
const setHeader = (headers, name, value) => { | ||
if (headers instanceof Headers) { | ||
headers.set(name, value); | ||
} else if (Array.isArray(headers)) { | ||
headers.push([name, value]); | ||
} else if (typeof headers === 'object') { | ||
headers[name] = value; | ||
} | ||
}; | ||
|
||
// Ensure opts.headers exists | ||
if (!opts.headers) { | ||
opts.headers = new Headers(); | ||
} | ||
|
||
// Set the 'Cookie' header | ||
setHeader(opts.headers, 'Cookie', sessionToken); | ||
} | ||
|
||
return PouchDB.fetch(url, opts); | ||
}; | ||
|
||
module.exports = () => { | ||
if (environment.isArchiveMode) { | ||
return new ArchivingDB(environment.archiveDestination); | ||
} | ||
|
||
return new PouchDB(environment.apiUrl, { | ||
ajax: { timeout: 60000 }, | ||
fetch: sessionCookieAwareFetch(), | ||
session: environment.sessionToken, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.