Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Davenport's use is ok in ES5 Browser when transpiled? #1

Open
bradws opened this issue Jan 29, 2017 · 4 comments
Open

Davenport's use is ok in ES5 Browser when transpiled? #1

bradws opened this issue Jan 29, 2017 · 4 comments
Assignees
Labels

Comments

@bradws
Copy link

bradws commented Jan 29, 2017

Hi there,

I have this working in Node v6 (using the Async/Await, etc) just fine, however I'm getting a 'GET http://localhost:3000/davenport 404 (Not Found)' error and a 'ZoneAwareError' in Chrome browser (I'm using Angular 2.4). Is Davenport ok to work in the ES5 browser?

I'm using Typescript 2.1 and can confirm the normal Async/Await feature is working in the browser. However, whenever I put this getMessage function in a class:

...
import Client, { CouchDoc } from 'davenport';
import {Foo} from './Foo';
...

export class AppComponent {

    private async getMessage() {
      let s = 'Some random string';
      
      const client = new Client<Foo>('http://127.0.0.1:5984', 'hello-world');  // error when this line is here
      
      this.myStrToDisplay = s;
    }

}

Typescript builds just fine, but the errors appear in the browser when I put the const client = new Client<Foo>('http://127.0.0.1:5984', 'hello-world'); line in there.

It can't seem to find Davenport. Maybe, are you able to provide some example code at all?

Cheers,
bradws

@bradws bradws changed the title Davenport's use ok in Browser Davenport's use is ok in ES5 Browser when transpiled? Jan 29, 2017
@nozzlegear
Copy link
Owner

Hey @bradws, as far as I know Davenport should be usable in the browser, although I haven't personally tested it and only use it in Node. I'll try to get this figured out and add something to the readme for it. Off the top of my head, the first thing I would do is make sure Davenport is definitely being loaded into your web page.

@nozzlegear nozzlegear self-assigned this Jan 30, 2017
@nozzlegear
Copy link
Owner

Alright, I've looked a little closer and Davenport can definitely work in the browser. I've added a browser-specific build to the NPM package, you'll find it under node_modules/davenport/bin/browser.js, but you can also just continue to require it like normal as long as you're using a bundler like webpack or browserify. 

The biggest problem that I ran into when using Davenport in the browser was related to CORS. I had to configure my CouchDB installation to allow CORS before Davenport was able to connect. You can find the CORS option at localhost:5984/_utils, in the configuration menu.

@bradws
Copy link
Author

bradws commented Feb 7, 2017

Hi again,

I'm still struggling to get Davenport working in Angular in the Browser. I'm using SystemJS.

But I can't even get it working in the browser at all:
In the root index.html I've imported ../node_modules/davenport/bin/browser.js, however how do i instantiate things?
const client = new Client( 'http://127.0.0.1:5984', 'helllo-world' ); nor
`const client = new Davenport.Client( 'http://127.0.0.1:5984', 'helllo-world' );' works.

It cannot see 'Client' nor 'Davenport'.

Can you provide some simple code examples at all?
Cheers.

@nozzlegear nozzlegear reopened this Feb 7, 2017
@nozzlegear
Copy link
Owner

No problem! I'll try to get some example files into the repo as soon as I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants