pouchdb / npm-browser

npm in your browser. Because why not. (UNMAINTAINED)
http://www.npm-browser.com
34 stars 7 forks source link

couchapp #2

Open calvinmetcalf opened 10 years ago

calvinmetcalf commented 10 years ago

if we change the url line to be

 $scope.couchdbUrl = location.protocol+ '//' +location.host + '/' + location.pathname.split('/')[1];

then we can just stick it in a couchapp and not worry about origin

nolanlawson commented 10 years ago

I still dream of having this actually work against skimdb. Right now it's not very impressive because it's not working against the main registry; but if it were, it'd be something neat to post to Hacker News to show off what PouchDB can do.

calvinmetcalf commented 10 years ago

but we could put the couch in our replica of skimdb

nolanlawson commented 10 years ago

Again, I just think it'd be more impressive if it comes directly from skimdb. Also probably would be faster.

NickColley commented 10 years ago

Would this work now?

nolanlawson commented 10 years ago

Just checked, but it seems https://skimdb.npmjs.com/registry still doesn't have CORS enabled. @isaacs?

isaacs commented 10 years ago

Somebody please tell me exactly what configs to set to enable read access, but no authentication.

daleharvey commented 10 years ago
$ export HOST=http://username:password@host.com
$ curl -X PUT $HOST/_config/httpd/enable_cors -d '"true"'
$ curl -X PUT $HOST/_config/cors/origins -d '"*"'
$ curl -X PUT $HOST/_config/cors/methods -d '"GET, HEAD"'
$ curl -X PUT $HOST/_config/cors/headers -d \
  '"accept, content-type, origin"'

should do it

isaacs commented 10 years ago

Right, but does that allow authenticated requests? If I have a session, can someone fetch my _users doc?

calvinmetcalf commented 10 years ago

that does not allow authenticated requests, you need to set Access-Control-Allow-Credentials: true for that

daleharvey commented 10 years ago

nope, you need to have the server configured to respond with

Access-Control-Allow-Credentials: true

with

curl -X PUT $HOST/_config/cors/credentials -d '"true"'

to send any cookies, also the headers is a whitelist so requests with authorization headers will be rejected

nolanlawson commented 10 years ago

I updated the gh-pages to use the real skimdb, so we'll know when it's working.

nolanlawson commented 10 years ago

So @izs, not sure what the status of this is, but here's an interesting thought:

On one of the NodeUp podcasts you mentioned admiring php.net because their search is crazy fast. I wanted to figure out why, and it turns out it's because they do an ajax request for just south of 1MB worth of json the first time you visit the site, which they immediately jam into localStorage. So by the time your eyeballs have digested the front page, you've already got most of the core APIs loaded locally, and you can type "arr" and immediately see "ArrayAccess", etc.

But npm could potentially do one better, since you could just use PouchDB with filtered replication and store a lot more than 1MB in the local database (e.g. fetch the top 100 packages, then the next 1000, or whatever). Plus you'd get pagination, which localStorage doesn't offer. I've also got a full-text search plugin in the works, but string splitting on whitespace plus map/reduce could probably do you just as well.

So anyway my point is that this crazy little demo app might not be so crazy after all. :) Would be nice to get CORS so we can experiment a bit more.