This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
endpoint to import documents into the database
- Loading branch information
John O'Malley
committed
Oct 22, 2016
1 parent
2631612
commit 7337a80
Showing
7 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ jspm_packages | |
# Optional REPL history | ||
.node_repl_history | ||
|
||
/public | ||
.idea | ||
.DS_Store | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
couchUrl: process.env.COUCH_URL || 'http://localhost:5984', | ||
searchHost: 'search-ocelot-6tqsxtl7pweckdfvle6ty47yiu.us-east-1.es.amazonaws.com', | ||
searchUserAccessKeyId: process.env.SEARCH_USER_ACCESS_KEY_ID, | ||
searchUserSecretAccessKey: process.env.SEARCH_USER_SECRET_ACCESS_KEY | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"name": "alice" | ||
}, | ||
{ | ||
"name": "bob" | ||
} | ||
] |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const agent = require('../src/agent') | ||
const { couchUrl } = require('./config') | ||
const express = require('express') | ||
|
||
const router = express.Router() | ||
|
||
router.post('/', (req, res, next) => { | ||
agent.post(`${couchUrl}/foobar/_bulk_docs`) | ||
.send({ docs: require('./docs.json') }) | ||
.then(({ body }) => res.json(body)) | ||
.catch(next) | ||
}) | ||
|
||
module.exports = router |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const _ = require('underscore') | ||
const aws4 = require('aws4') | ||
const https = require('https') | ||
|
||
module.exports = ({ host, credentials }) => { | ||
return ({ path, method, body, headers = {}, json = true }) => { | ||
const options = { | ||
host, | ||
path, | ||
method: method || (body ? 'POST' : 'GET'), | ||
headers | ||
} | ||
if (_(body).isObject()) { | ||
options.body = JSON.stringify(body) | ||
headers['Content-Type'] = 'application/json; charset=utf-8' | ||
} else if (_(body).isString()) { | ||
options.body = body | ||
} | ||
|
||
const signed = aws4.sign(options, credentials) | ||
|
||
return new Promise((resolve, reject) => { | ||
const request = https.request(signed, (res) => { | ||
let responseBody = '' | ||
res.on('data', chunk => responseBody += chunk) | ||
|
||
const result = () => json && responseBody ? JSON.parse(responseBody) : responseBody | ||
|
||
res.on('end', () => { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
resolve(result()) | ||
} else { | ||
reject({ status: res.statusCode, body: responseBody }) | ||
} | ||
}) | ||
}) | ||
request.on('error', reject) | ||
request.end(signed.body || '') | ||
}) | ||
} | ||
} |